React: <BuilderComponent> doesn't rerender when user attributes change
See original GitHub issueWe have a basic Builder component:
<BuilderComponent model="home-pages" />
If we call builder.setUserAttributes
before this renders, it will pass the correct attributes to the Builder API and render the correct content.
If we then call builder.setUserAttributes
after this renders (e.g. if the user signs in), it doesn’t show the new content.
Problem 1: Builder doesn’t fetch new content from the API. We can tell this is a problem because there’s nothing in the network tab when we call builder.setUserAttributes
.
Problem 2: Builder fetches new content from the API, but the component doesn’t update. We can tell this is a problem because even if we manually fetch new content and pass it into <BuilderComponent>
, it doesn’t update:
// doesn't work:
function MyComponent() {
const [content, setContent] = useState(null)
useEffect(() => {
builder.get('home-pages').promise().then(setContent)
})
return <BuilderContent model="home-pages" content={content} />
}
// works:
function MyComponentWithKeyUpdate() {
const [content, setContent] = useState(null)
useEffect(() => {
builder.get('home-pages').promise().then(setContent)
})
return <BuilderComponent model="home-pages" content={content} key={content.id} />
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (12 by maintainers)
Top Results From Across the Web
How and when to force a React component to re-render
The component did not change, so there was no re-rendering trigger. Here's why. React evaluates state changes by checking its shallow equality ...
Read more >React: why child component doesn't update when prop changes
Update the child to have the attribute 'key' equal to the name. The component will re-render every time the key changes.
Read more >When does React re-render components? - Felix Gerschau
Changing the state means that React triggers an update when we call the setState function (in React hooks, you would use useState )....
Read more >React doesn't always trigger a re-render on setState
For new React developers, it is common to think that setState will trigger a re-render. But this is not always the case. If...
Read more >React re-renders guide: everything, all at once - Developer way
When the value in Context Provider changes, all components that use this Context will re-render, even if they don't use the changed portion ......
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 FreeTop 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
Top GitHub Comments
btw we found a bug that with the last release with symbols not displaying in the editor, so when you upgrade I’d recommend using
@builder.io/react@1.1.17
😃will also release again if needed when we find what might be causing unsubscribing to not always work
Yeah @antonhalim it follows the ES Observable spec so you just do