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.

All inputs re-rendering even without validation.

See original GitHub issue

Heya, I’ve got 25ish textfields in a Form in v1.10.9. Every time I enter anything in one of them, they all re-render, taking about 250-300ms per keystroke.

I’ve checked the gotchas section about validation, and I’ve culled mine down so there’s no validation, no external onChange/onBlur being passed in, no functions being created inline on any components etc. If I console.log in the render() of <InformedTextField/> I see a render for all 25 instances, every keystroke or blur.

My main class only has this in the render() function:

<Form>
  {({ formApi }) => (
  <React.Fragment>
	<InformedTextField
                    field="name"
                    label="Name"
                    initialValue=""
        />

... X 25 or so

 	<Button label="Add User" onClick={formApi.submitForm} disabled={this.busy} />
   </React.Fragment>
  )}
</Form>

<InformedTextField/> is a custom class which wraps the Material-UI TextField. It doesn’t do any validation or setting of state and simply exports export default asField(InformedTextField); after setting the appropriate value and onChange/onBlur functions.

The change/blur functions of <InformedTextField/> are set on the TextField itself like:

onChange={this.handleChange}
onBlur={this.handleBlur}

and the functions are:

 handleChange = event => {
    this.props.fieldApi.setValue(event.target.value);
    //if (this.props.onChange) {
    //  this.props.onChange(event);
    // }
  };

  handleBlur = event => {
    this.props.fieldApi.setTouched(true);
    //if (this.props.onBlur) {
    //  this.props.onBlur(event);
    //}
  };

It’s really not usable currently with all these form items, so I’m assuming I must be missing something. Any suggestions on what I could look at to prevent everything from re-rendering?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
timothyallancommented, Dec 4, 2018

Thanks all, looks like manual shouldComponentUpdate check is the only way to do it!

1reaction
joepuzzocommented, Dec 4, 2018

Eventually when i have more time im going use hooks instead of HOCs and hopefully these issues will be easier to debug/or non existent

Read more comments on GitHub >

github_iconTop Results From Across the Web

React - How to prevent re-rendering of all the input fields ...
3 Answers 3 · once Input changes , the form state is updated. · Only Content will rerender bcs it's state chagned, but...
Read more >
Every input field in form rerenders when just one changed #367
Currently, all other input in the same form rerender, sometimes like 4 times each (when it comes to validation). Any suggestions?
Read more >
When does React re-render components? - Felix Gerschau
When the VDOM gets updated, React compares it to to a previous snapshot of the VDOM and then only updates what has changed...
Read more >
Learn how to force react components to rerender without ...
A complete guide on component re-rendering. Here you will learn how to force react components to rerender without calling the set state.
Read more >
Why I Spent 3 Hours Trying to Fix a React Re-render Issue
I was building a highly dynamic and extensible validation form, so you can add a new input field as an object to the...
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