Skip to content

Instantly share code, notes, and snippets.

@trueadm
Last active November 15, 2017 13:57
Show Gist options
  • Save trueadm/6a25a327771cd9d92d7bceb4d3127212 to your computer and use it in GitHub Desktop.
Save trueadm/6a25a327771cd9d92d7bceb4d3127212 to your computer and use it in GitHub Desktop.

API #1 for functional components with state

Acts similar to current API, where first argument is props, second is state. The third argument acts like a bag and contains context and any other arguments that would have been passed explicitly before plus an functions to update state.

Mounting

  • initialState(props, context)
  • willMount(props, state, {context, reduce, setState})

Rendering

  • render(props, state, {context, reduce, setState})

Updating

  • willReceiveProps(props, state, {nextProps, context, reduce, setState})
  • shouldUpdate(props, state, {nextProps, nextState, context, nextContext})
  • willUpdate(props, state, {nextProps, nextState, context, nextContext})
  • didUpdate(props, state, {prevProps, prevState, reduce, setState})

Unmounting

  • willUnmount(props, state, context)

Error Handling

  • dillCatch(props, state, {context, reduce, setState})

API #2 for functional components with state (ReasonReact-like)

Similar to ReasonReact's component API (with some obvious differences for things like context and bits that ReasonReact doesn't support but we likely will need to) where each argument typically is a version of "this" ("self" in Reason land). So the first argument might be "current self" containing props, state and context, the second argument might be "next self" again, containing props, state and context. I made the last argument a bag of functions we can do. If there was only reduce this argument would likely only be reduce rather than an object.

Mounting

  • initialState({props, context})
  • willMount({props, state, context}, {reduce, setState})

Rendering

  • render({props, state, context}, {reduce, setState})

Updating

  • willReceiveProps(self: {props, state, context}, props, {reduce, setState})
  • shouldUpdate(self: {props, state, context}, nextSelf: {props, state, context})
  • willUpdate(self: {props, state, context}, nextSelf: {props, state, context})
  • didUpdate(lastSelf: {props, state, context}, self: {props, state, context}, {reduce, setState})

Unmounting

  • willUnmount({props, state, context})

Error Handling

  • dillCatch({props, state, context}, {reduce, setState})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment