which is better approach for useState
Unanswered
Naeemgg posted this in #help-forum
NaeemggOP
const [firstName, setfirstName] = useState<string>("")
const [middleName, setmiddleName] = useState<string>("")
const [lastName, setfirstName] = useState<string>("")
OR
const [Name, setName] = useState({firstName:"", middleName:"",lastName:""})which method will cause least amount of rerenders???
4 Replies
@Naeemgg ts
const [firstName, setfirstName] = useState<string>("")
const [middleName, setmiddleName] = useState<string>("")
const [lastName, setfirstName] = useState<string>("")
OR
const [Name, setName] = useState({firstName:"", middleName:"",lastName:""})
which method will cause least amount of rerenders???
well if you want "least amount of re renders" use ref
the component will re render everytime state changes
For me the second one
But depend on your requirements