I am using functional components
.I have 2
radio buttons and a submit
button.On submit button I am not able to get updated value
.
here is my code https://codesandbox.io/s/peaceful-microservice-ywdoe?file=/src/App.js
step to reproduce
no
yes
.then click submit button.it should show updated value of state. but it is showing initial state why ??button submit handler
const buttonHandler = useCallback(async e => {
e.preventDefault();
console.log(state);
}, []);
if change blank array to one item in array state like this
.it works correctly, but it re-render button component when I change the state
. any better solution ??? to prevent re-rendering and get updated state?
const buttonHandler = useCallback(async e => {
e.preventDefault();
console.log(state);
}, [state]);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.