react-parm - Handle react classes with more functional purity
at github.com▼2 up and 2 down, posted by
2 up and 2 down, posted by
Can the person who downvoted explain the reason? This is actually facilitating a paradigm we use in a lot of components in our workplace, so if there is an issue or reservation with it then it would be good to know.
The goal here is functional purity, so that all of your instance methods are encapsulated and easily testable. There are usually a decent amount of hoops to jump through if you want to test lifecycle methods, especially ones revolving around updates. There is also the benefit of code terseness. Example: function componentDidMount() { const {getThing, id} = this.props; getThing(id); } vs const componentDidMount = ({props: {getThing, id}}) => getThing(id); The latter is much less verbose, while at the same time being self-documenting. In the former case, you need to introspect the function to determine what is being used (a function and id from props), whereas that information is readily available in the function signature in the latter case. There are many other examples where your mitigating argument can be applied ... for example, recompose lets you add lifecycle methods to functional components, when converting it to a class is "not that hard". This paradigm has helped greatly speed up my velocity, but like anything else, opinion and preference come into play, so YMMV.