I am trying to convert this cool <canvas> animation I found here into a reusable React component. It looks like this component will need one parent component for the canvas and many child components for function Ball() .
For performance reasons, it would probably be better to turn Balls into stateless components since there will be a lot of them. I am not so familiar with creating stateless components, and I was wondering where I should define the functions this.update() and this.draw , which are defined in function Ball() .
Functions for stateless components go inside the component or outside? In other words, which of the following is better?
1:
const Ball = (props) => { const update = () => { ... } const draw = () => { ... } return ( ... ); }
2:
function update() { ... } function draw() { ... } const Ball = (props) => { return ( ... ); }
What are the pros / cons of each and are they better for specific use cases like mine?
source share