Matthews Masia
Matthews Masia

Reputation: 29

Does change in Props Data Change the state of components or will it render the change?

I am currently learning React js, and the differences between props and States are apparent.

But will the change in data passed in the prop cause the component to re-render or will it still be static with the data passed initially?

I still have reservations on props values changes, if it does cause a re-render of the component(not changing the data within the components)?

Upvotes: 1

Views: 1019

Answers (1)

Tea_Lover_418
Tea_Lover_418

Reputation: 316

A change in props will cause a re-render.

If you do not want this you can use a state like this:

const Component = (props) => {
  const [firstRenderProps] = useState(props);

firstRenderProps will always have the same value after a re-render

Upvotes: 1

Related Questions