Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input lag / many rerenders #1739

Closed
tobeycodes opened this issue Aug 9, 2019 · 4 comments
Closed

Input lag / many rerenders #1739

tobeycodes opened this issue Aug 9, 2019 · 4 comments
Labels

Comments

@tobeycodes
Copy link

🐛 Bug report

Current Behavior

If I make a change to a input it re-renders all the fields 2 times (in the codesandbox example with the autosave component comment out). If I enable the autosave (as the codesandbox is when opened) if you make a change to an input it rerenders each field 6 times.

When I have 30 fields. It is doing thousands of rerenders :(

Expected behavior

When making changes to fields it should not be re-rendering the fields more than once and my understanding of FastField is that only the single field will re-render.

Reproducible example

https://codesandbox.io/s/adoring-boyd-zsfog?fontsize=14

Suggested solution(s)

I do not know

Your environment

Software Version(s)
Formik 2.0.1-rc.12
React 16.8.6
TypeScript N/A
Browser Firefox
npm/Yarn N/A
Operating System MacOS
@ersel
Copy link

ersel commented Aug 14, 2019

I run into a similar problem, and rolled my own "fast field" which looks like this...

import React from "react";
import { Input } from "reactstrap";
import { connect, getIn } from "formik";

class FastInputField extends React.Component {
  shouldComponentUpdate(nextProps) {
    const { name, formik } = this.props;
    if (nextProps.name !== name) {
      return true;
    }
    const nextValue = getIn(nextProps.formik.values, name);
    const previousValue = getIn(formik.values, name);
    if (nextValue !== previousValue) {
      return true;
    }
    return false;
  }

  render() {
    const { name, formik, row, validateForm } = this.props;
    const value = getIn(formik.values, name);

    return (
      <Input
        value={value}
        type="text"
        onChange={e => {
          formik.setFieldValue(name, e.target.value);
        }}
      />
    );
  }
}

export default connect(FastInputField);

@johnrom
Copy link
Collaborator

johnrom commented Aug 31, 2019

@schrapel in v2 I don't believe fast field is implemented at this time. There is some movement on this PR: #1772

@stale stale bot added the stale label Oct 30, 2019
@100ideas
Copy link

@ersel thanks for sharing your <FastInputField /> solution!

I put together a formik-playground demo app to help myself learn and I included a section demonstrating your approach - hope that's ok!

https://github.com/100ideas/100ideas-formik-playground

https://ideas-formik-playground.web.app/

@ersel
Copy link

ersel commented Oct 31, 2019

No worries @100ideas , my pleasure.

@stale stale bot added the stale label Dec 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants