question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Component doesn't react with new data

See original GitHub issue

The 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 the fields 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
pavanpodilacommented, Mar 21, 2018

@hellofantastic I think this could be a nice PR 😃

1reaction
jeroen-corsiuscommented, Dec 20, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found