I'm using functional components.
<Column customFunc={myFunc} />
How should myFunc be defined?
function myFunc(e) { // code }
or
const myFunc = (e) => { // code }
Only when defining it using function
keyword aka function declaration, I get this error from ESLint: JSX props should not use functions eslint (react/jsx-no-bind)
It looks like function expressions are not regarded as functions by ESLint and that's why it doesn't show that warning when they're used. Aside from hoisting and immutability, how should I define my functions inside a functional component? Does it have any impact on the way components render?
Also, if myFunc
(which is defined inside another component) returns a JSX, is that considered bad?
function myFunc(props) { <CustomJSX {... props} controlParentState={editParentState} /> }
I get ESLint error/warning saying: Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component “App” and pass data as props. eslint (react/no-unstable-nested-components)
My problem is, if I define myFunc
outside of parent component, how can I pass props
to it when I call it (and would props
have controlParentState
in this case and would it be able to alter parent state)?