Initial store data is components is always `null`, then loads + re-renders second time to a correct value automatically
See original GitHub issueThis isn’t the end of the world, as I can currently wrap every single component and every store value in an if check to see if the data has actually been loaded, but what seems to be happening is that all components mount and render twice – once with an empty store and then one with the “real” value.
Has anyone seen/heard of this behavior before and have any idea what might be behind it/how to debug? Thank you =)

const Table = () => {
const db = useStoreState(state => state.db)
const tables = useStoreState(state => state.tables.entries)
const { name } = useParams()
console.log("[TABLE COMPONENT]")
console.log("DB:", db)
console.log("TABLES:", tables)
if (!tables || !db) return null
const table = tables.find(it => it.table_name == name)
const columns = table?.columns
.map(it => it.column_name)
.map(name => ({ Header: name, accessor: name }))
const req = useQuery(`/table/${name}`, () =>
db.selectRows(makeRowSelectArgs(table, { limit: 100 }))
)
switch (req.status) {
case "loading":
return <h1>Loading Tables...</h1>
case "error":
return <h1>Error fetching tables: {req.error.message}</h1>
case "success":
return <TableComp columns={columns} data={req.data} />
}
}
Without if (!tables || !db) return null (or equivalent on every component) this happens:

Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
Why is my React component is rendering twice?
Everything seems to be working fine except it renders twice... The first one renders the phone number and zero points. The second time...
Read more >React Hooks cheat sheet: Best practices with examples
Declaring a state variable is as simple as calling useState with some initial state value, like so: useState(initialStateValue) . const ...
Read more >Preventing infinite re-renders when using useEffect and ...
Your first render runs, and because data is falsey, render returns null and kicks off useEffect · useEffect runs, fetching your data, and...
Read more >Update on Async Rendering – React Blog
The new static getDerivedStateFromProps lifecycle is invoked after a component is instantiated as well as before it is re-rendered. It can ...
Read more >5 Ways to Avoid React Component Re-Renderings
React components have evolved a long way from their inception. ... The above example has a toggle that re-renders the component each time...
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’ll let you know when the patches are released for test.
We are on it. But of course, there are breaking changes. Hope we can do it soon. I’ll let you know. Thanks again.