I am refactoring my application to make more components of idle / clean components; that is, they are just functions. However, I noticed that some components will need to connect to the redux repository through mapStateToProps
. This makes me do something like this:
const someComp = (props) => { const { funcFromReduxStore, } = props; return ( ... <SomeComponent func={ funcFromReduxStore(myArgs) } ... ); };
This will not work because I am executing funcFromReduxStore
. An easy solution is to wrap the support in an arrow function. However, this causes a lot of unnecessary b / c re-rendering, the function will not be bound.
Then the question arises: how to bind a function in a stateless component?
Is it still stateless if I make it a class without a constructor and create a class instance field like this:
class someComp extends React.Component { const { funcFromReduxStore, } = this.props, wrapper = (x) => funcFromReduxStore(x)
I have no constructor or state. I want to keep comopnent stateless, but I also want to bind a function to avoid unnecessary retries. I also want to continue to hold him stateless. B / c React said there will be performance benefits for stateless people. Does this qualify as a workaround?
source share