use multiple state of react

Solutions on MaxInterview for use multiple state of react by the best coders in the world

showing results for - "use multiple state of react"
Jocelyn
02 Nov 2020
1function Form() {
2  // 1. Use the name state variable
3  const [name, setName] = useState('Mary');
4
5  // 2. Use an effect for persisting the form
6  useEffect(function persistForm() {
7    localStorage.setItem('formData', name);
8  });
9
10  // 3. Use the surname state variable
11  const [surname, setSurname] = useState('Poppins');
12
13  // 4. Use an effect for updating the title
14  useEffect(function updateTitle() {
15    document.title = name + ' ' + surname;
16  });
17
18  // ...
19}
similar questions
queries leading to this page
use multiple state of react