`Box` `height` doesn't reset on re-render
See original GitHub issueIt appears that the height
property might be updated when re-rendering a component, though I may be misunderstanding something!
Here’s a quick example:
// We're waiting for an async process, so we'll want a loading state.
const [results, setResults] = useState([])
useEffect(() => {
loadResults().then(output => {
setResults(output)
})
}, [])
// Loading state if we're still waiting on the results
if (results.length === 0) {
return (
<Box height={3}>
<Color grey>Loading...</Color>
</Box>
)
}
// Once the results load, show the list:
return (
<Box flexDirection="column">
<Color>1</Color>
<Color>2</Color>
<Color>3</Color>
<Color>4</Color>
<Color>5</Color>
</Box>
)
I would expect to see all five numbers printed out, but only see the first three:
$ yarn dev
1
2
3
When run with debug=true
:
PS – would be nice if
debug
mode added in a newline in between renders!
$ yarn dev --debug
Loading...
1
2
31
2
Note: I just swapped height
out with marginTop
/marginBottom
here and it works fine!
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Flex-box items don't re-render correctly on chrome
A js workaround is to force the layout to re-render by quickly changing the items padding by 1px back and forth, but I...
Read more >Re-render a React Component on Window Resize | Pluralsight
Now we have set up some internal state, dimensions , that has height and width properties. Inside handleResize , we no longer simply...
Read more >resetting form values inside lit elment doesnt't trigger re-render
Description I have a form, having 3 input elements, I want to set it to null value (reset), after the form is submitted,...
Read more >Forcing state reset on a React component by using the key prop
One solution is to define componentWillReceiveProps , check if activeChat prop has changed and if so reset the message field manually. This solution...
Read more >Just Say No to Excessive Re-Rendering in React - GrapeCity
Typically, React performs well out of the box using techniques to reduce ... in a consequent re-render of the MovieDetails which does not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I can’t believe I just spent an entire day debugging React internals and all it was is just out-dated
react-reconciler
dependency that I had. Kill me now.Yeah, I had the exact same problem few days ago. Replacing
useEffect
withuseLayoutEffect
has solved it for me. Check out https://github.com/vadimdemedes/ink/pull/147#issuecomment-531598933. TLDR isuseEffect
doesn’t run soon enough after Ink renders a frame, so process exits beforesetTimeout
is executed in your code.useLayoutEffect
however, ensures to run the effect immediately after render.