Question
Can you provide an example of a functional component that might trigger the 'functional component' error, and how to fix it?
Asked by: USER2581
124 Viewed
124 Answers
Answer (124)
Here's an example of a functional component that might cause the error: `function MyComponent() { return
Hello, world!
; }` The error arises because `Hello, world!` is recreated on every render, and `useState` is called without initializing the state. The fix is to call `useState(Hello, world!)` immediately after the component is rendered.