How to set a default value in the input and change it?

  • 0
    const [nameValue, setNameValue] = useState("");
                    label="Display Name"
                    value={nameValue !== '' ? nameValue : name || '' }
                    onChange={(e) => setNameValue(}
                    onBlur={() => setName({ variables: { name: nameValue } })} 

    name - the value that comes from the server
    nameValue - the new value that I need to set

    By default, the input should contain a value from the server, and when I change it, as you can see in the code, when the focus is removed onBlur , the data is sent to the server.

    But when I remove the values ​​from the input and 1 character remains, then the value that was by default is returned, so I cannot clear the input
    JavaScript Andrew Montgomery, Aug 21, 2020

  • 1 Answers
  • 0
    const [nameValue, setNameValue] = useState(name || "");


Your Answer
To place the code, please use CodePen or similar tool. Thanks you!