I am pretty much completely new to React. I've read the documentation and watched some YT video's. Now I am trying 'convert' some of this React class component that I found online to a functional component. This is how far I've come: My functional component(codesandbox).
It is a component to automatically wrap SVG text using tspan
elements based on a user input field.
I am specifically having a hard time with the useEffect hook. As I understand it, it should function as the equivelant of componentWillMount
and componentDidUpdate
. Now I've got everything pretty much setup, but it does not yet update the Text
component whenever new text is added in the textarea. I believe this is because I have to do something in the useEffect
hook in the Text
component:
useEffect(() => {
//something so that lines get updated if the user input changes?
}, [lines]);
The things I've tried resulted in an infinite loop. See: Can I use set state inside a useEffect hook.
Could someone point me in the right direction? Feel free to fork the codesandbox :)