Skip to content

Latest commit

 

History

History
51 lines (36 loc) · 2.04 KB

File metadata and controls

51 lines (36 loc) · 2.04 KB

Pure function example

Running the application

yarn install && yarn start

Open Pure function example subpage.

New dependencies

Pure function components

Reac views use immutability to make components easier to understand and to improve performance. JavaScript classes are not a good representation of an immutable computation. Therefore React allows components to be defined using simple functions.

A pure function component receives props as an argument and must return a React node (JSX).

Components in the example

  • App has been reverted to not increase amount of comments at an interval.
  • Comment has been implemented as a pure function component.
  • CommentForm has been implemented as a pure function component.
  • CommentList has been implemented as a pure function component.

Prop validation

All components were added prop validations. Prop validation help to catch errors in data propagation early in development. They are a poor-man's version of typing. eslint rules "react/prop-types" checks that all props are accompanied by validation. Prop validation is removed when building a production release.

Check out the components or documentation for examples on how to validate props.

Note that prop validation linting was turned off for the earlier, props and state examples.