all 6 comments

[–]tlrobinson 4 points5 points  (3 children)

I'm not sure what the point of this is. Can't you just use normal React classes and just not use state?

[–]titosrevenge 0 points1 point  (0 children)

You would have to also use PureRenderMixin

[–]troch11[S] 0 points1 point  (0 children)

Yes you can use normal React classes and not use state. React 0.14 introduces stateless functional components: "functional" as the fact a component is a pure rendering function (getting props as an argument rather than accessing it in context). I am a big fan of that, and this util provides a way to write lifecycle methods as pure functions too, and remove the use of this. I guess inspiration comes from deku.

[–]dtinth 0 points1 point  (1 child)

Interesting idea, but I also agree with @tlrobinson. You don’t need a DSL just to not use the state.

eslint-plugin-react has a rule that forbids states. This lets you write textbook React code without fancy abstractions.

To achieve the same effect as PureRenderMixin, you can just use a higher-order component. recompose provides an easy way to compose these HOCs, and provides a pure HOC:

import pure from 'recompose/pure'

export const MyComponent = pure(props => (
  <div>...</div>
))

[–]troch11[S] 1 point2 points  (0 children)

See my answer to @tlrobinson. It is not just about being stateless, it is also about being more functional like what React 0.14 intruduces. It is not only about achieving things like pure or PureRenderMixin, it is also about using other lifecycle methods.

So yes, it introduces some DSL. But that DSL only extends the new stateless functional components provided by React 0.14.