V
V
Vlad2020-04-19 19:10:39
React
Vlad, 2020-04-19 19:10:39

Can I pass in initial state useState props?

I pass props to the hook state as the initial state . As a result, my name is undefined . In this case, if you display itemChange.name in the console, then everything works fine.

const [name, setName] = useState(itemChange.name);

Can I generally set the initial state in this way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-04-19
@hzzzzl

everything works

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question