As title. I try to set component state from child through callback given by parent. Demo is in https://codepen.io/jadecubes/pen/wvYxKEL
The callback looks like
A = () => {
const [info, setInfo] = useState(["Hello world."]);
return (
<>
<B
onChange={() => {/*I am callback*/
info.length = 0;
info.push("Hey!");
setInfo(info);
}}
/>
<h1>{info}</h1>
</>
);
};
Clicking button doesn't change the text. But if it's something like below, it changes normally.
A = () => {
const [info, setInfo] = useState(["Hello world."]);
return (
<>
<B
onChange={() => {/*I am callback*/
setInfo(['hey']);
}}
/>
<h1>{info}</h1>
</>
);
};
Any suggestions are welcome.