Re-render Child Component By Changing Key (opens in new tab)
Today I had a situation where I wanted a child component to re-render on command. The solution I found was to to put a key on it, and then change the key when the re-render is desired. const Parent = () => { const [childKey, setChildKey] = useState(0); const rerenderForm = () => { setChildKey(childKey + 1); } return ( <> Rerender the form! ) } In this example, which the button is clicked, our childKey is increme...
Read the original article