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] - I'm having an issue with changing value dynamically

See original GitHub issue

I want to dynamically change the value to a default value I made when I click on a button.

My code looks like this:

const numberDefault = 1;
const [enteredNumber, setEnteredNumber] = useState(numberDefault);
const resetInputHandler = () => {
    setEnteredNumber(numberDefault);
}


<NumericInput
        value={enteredNumber}
        ... />
<Button title="Reset" onPress={resetInputHandler} />

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
Tyak99commented, Nov 17, 2019

I am having the same issue. When props.value changes, The NumericInput state.value does not update. NumericInput rerenders, but the value of state.value remains the same. Checking for that in the NumericInput component would solve for it. Something like:

 componentDidUpdate(prevProps) {
        if (prevProps.value !== this.props.value) {
            this.setState({
                value: this.props.value,
                lastValid: this.props.value,
                stringValue: this.props.value.toString()
            });
        }
    }
1reaction
phongbksneepcommented, May 31, 2022

I am having the same issue. When props.value changes, The NumericInput state.value does not update. NumericInput rerenders, but the value of state.value remains the same. Checking for that in the NumericInput component would solve for it. Something like:

 componentDidUpdate(prevProps) {
        if (prevProps.value !== this.props.value) {
            this.setState({
                value: this.props.value,
                lastValid: this.props.value,
                stringValue: this.props.value.toString()
            });
        }
    }

It’s right, you can try this

    <NumericInput
        value={0}
        initValue={enteredNumber}
    ... />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript change object property values dynamically error
I'm trying to dynamically change object property values based on the property type, e.g., replace all object string properties with "***".
Read more >
Error when trying to add dynamic value
I'm having same issue on different flows. All since a week ago. Not found the reason yet and even recreating the steps, I...
Read more >
How To Add Dynamic Variable To A List - Studio - UiPath Forum
Hi, I'm running into a problem where I have a dynamic variable that changes through each iteration not being added to a list....
Read more >
Salesforce Dynamic Forms: Overview & Deep Dive Tutorial
The closest resolution we've had is to create multiple page layouts and different profiles, which is labor and config intensive. Well, no more....
Read more >
How to dynamically set Google Sheet and Worksheet custom ...
Zapier had trouble retrieving custom fields from Google Sheets. ... on how to dynamically update the Sheet and Worksheet custom values and ...
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