nico
Published in : 2022-04-16

[React] How to know which state was updated when a render is triggered in a function component ?

React js

Hello, all i noticed that my component was rendered three times when I update an input in my form.

It is not good and feel like a performance problem.

So my question is : when a component is rendered, how can we know what state was updated when the function component is rendered?

That way I will try to optimize the code so the function component is rendered only once when I update the input of the form.

Thanks for your help

 

Comments

Mohamed Atef Date : 2022-04-16

Best answers

51

Best answers

51

I prefer to use Formik for Reactjs forms it's away better than using states and updating states on input change 

nico Date : 2022-04-16

Best answers

4

Best answers

4

Ironic, I use Formik in my case !

 

  const formik = useFormik({

    initialValues: {

      xxx

    },

    validate,

    onSubmit: (values) => {

      cancelForm.current = false;

 

      onPostData("/xxxx/Add", values);

 

      formik.handleReset();

    },

  });

export function yyy({

 xxx

}) {

  …


 

  console.log(

    "%c xxx called",

    "background: blue; color: #FFF"

  );

I see the call %c xxx called" 3 times each time I update one input…

so it seems overkill

nico Date : 2022-04-16

Best answers

4

Best answers

4

it seems in devtool there is one option: 

but do you know how to use it?

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

React Redux : Connect is not called
Publish date: 2022-03-02 | Comments: 1

Tag: React js

[solved] Render/Show a custom option in Autocomplete Material UI?
Publish date: 2021-12-22 | Comments: 2

Tag: React js

[solved] Expected a conditional expression and instead saw an assignment
Publish date: 2021-11-29 | Comments: 0

Tag: React js

Best way to update the state in one class component from the redux store?
Publish date: 2022-03-30 | Comments: 3

Tag: React js

React Component setState doesn't update my property
Publish date: 2022-03-29 | Comments: 2

Tag: React js

Unexpected mix of '&&' and '||' Reactjs
Publish date: 2021-10-30 | Comments: 0

Tag: React js