You should avoid setting state directly in the render() method. The render method should be pure, meaning it should not modify the component's state. Setting state in render would cause an infinite loop of re-rendering since changing state triggers another render cycle.