Component doesn't react with new data
See original GitHub issueThe issue:
- The property
fields
in my application <QueryBuilder /> is using dynamic data that comes from an API call. But when the data is retrieved, the <QueryBuilder /> doesn’t render the new options in thefields
dropdown.
Expected behavior:
- Having the component to re-render with the updated property.
Code sample:
// # Retrieving the data
componentWillMount() {
getQueryConditions().then((result) => {
const queryConditions = result.data
.map(condition => ({
name: condition.Name.replace(/\s+/g, ''),
label: condition.Name,
}));
this.setState({ conditions: queryConditions });
});
}
// # Rendering the component
renderQueryBuilder = (conditions) => {
if (!this.state.conditions.length) return <LinearProgress />;
return (<QueryBuilder
fields={conditions}
onQueryChange={this.logQuery}
/>);
};
For now I was able to circumvent this by interrupting the render completely until there’s data. But is the fact that the component doesn’t re-render a feature by design?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top Results From Across the Web
React Component data not being displayed - Stack Overflow
I am new to React and trying to write ...
Read more >React.Component
React doesn't call UNSAFE_componentWillReceiveProps() with initial props during mounting. It only calls this method if some of component's props may update.
Read more >State and Lifecycle - React
This page introduces the concept of state and lifecycle in a React component. You can find a detailed component API reference here.
Read more >Suspense for Data Fetching (Experimental) - React
It's a mechanism for data fetching libraries to communicate to React that the data a component is reading is not ready yet. React...
Read more >Uncontrolled Components - React
In React, an <input type="file" /> is always an uncontrolled component because its value can only be set by a user, and 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
@hellofantastic I think this could be a nice PR 😃
I’m facing a similar issue: What I’m trying to accomplish is resetting the QueryBuilder to it’s initial state, by updating the query-property. The component doesn’t re-render on this unfortunately.