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.

[BUG] - Value doesn't change when component parent is rendered

See original GitHub issue

Hi guys,

I have NumericInput component inside another one with the following structure:

Class Product {
    this.state = {
        quantity: 2;
    }
render(){
    return (<View>....</View>
    <NumericInput
       ...
        value={this.state.quantity}
        onChange={...} />)
    }
}

As the Produc is rendered, because of quantity state update, NumericInput doesn’t render itself. Inside the NumericInput I see the old quantity value.

I’d like the quantity value is rendered inside NumericInput component as well.

Enviorment (please complete the following information):

  • Version: 1.8.3
  • React Native version: 0.61
  • Device: Android 7

Can I solve the bug? Any workaround?

Thanks in advance, Simone

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
a777medcommented, Nov 28, 2020

Hi,

Add this to the NumericInput component (NumericInput.js) and it will work just fine.

componentDidUpdate(prevProps) {
  if (prevProps.value !== this.props.value) {
    this.setState({
      value: this.props.value,
      stringValue: this.props.value.toString(),
    });
  }
}
0reactions
huy-lvcommented, Sep 23, 2022

@simo385 how did you resolve it

Read more comments on GitHub >

github_iconTop Results From Across the Web

React: Parent component re-renders all children, even those ...
Yes , by default if parent changes all its direct children are re-rendered but that re-render doesn't necessarily changes the actual DOM ...
Read more >
Why React Child Components Don't Update on Prop Changes
In React, it's a common problem to have child components that don't re- render when you expect them to. In particular, a common...
Read more >
Children don't re-render when parent component is optimised
I am seeing something that looks like a bug and have written a simple test case for it. Please refer to this WebpackBin...
Read more >
Re-rendering Components in ReactJS - GeeksforGeeks
The code gives a message each time the component's render function is called. Each time the count button is clicked state change is...
Read more >
React.Component
These methods are called when there is an error during rendering, in a lifecycle method, or in the constructor of any child component....
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