0

I'm get this error Warning: setState(...): Cannot update during an existing state transition (such as within render or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to componentWillMount for

<a key={brand} onClick={this.someFn(Brands[brand])}>

2 Answers 2

1

I strongly advise against mutating the state inside render() methods. In fact it is strongly suggested by the maintainers of React, to keep the render() method as a pure function.

If you want to change the state between different components, for example if you have a sidebar, the most robust solution is to use Redux or an equivalent application state library.

Sign up to request clarification or add additional context in comments.

1 Comment

I can't use redux or another state library. I think I'll use function to pass icon from the child component to the parent component without any state modification
0
 <a key={brand} onClick={() => this.someFn(Brands[brand])}>

call it with an arrow function

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.