I noticed that when I replace specific items in a data set and use a useState update it will only rerender on primatives.
Ex: this updates something
but does not rerender
function TEST()
{
const [something, setSomething] = useState(["this", "works", "?"]);
return <div>
<Button onClick={()=>{
let tempSomething = something;
tempSomething[1] = "can work";
setSomething(tempSomething);
}}>CHANGE</Button>
{something}
</div>
}
However, if you were to replace the parameter in setSomething()
with either a literal or another created variable that does not link to something
, then it will trigger a rerender. What is the issue here?
These work:
setSomething(["something", "new"]);
or
let r = ["why", "?"]
setSomething(r);