Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FaCC maybe worth considering instead of context types #4

Open
rmoorman opened this issue Nov 9, 2017 · 0 comments
Open

FaCC maybe worth considering instead of context types #4

rmoorman opened this issue Nov 9, 2017 · 0 comments

Comments

@rmoorman
Copy link

rmoorman commented Nov 9, 2017

Instead of using the context feature of react to pass through data to the timer rendering component, this could also be achieved using a function as child component style API.

Using the example given within the readme, this:

const Countdown = (props, context) => {
  const d = new Date(context.remaining);
  const { seconds, milliseconds } = {
    seconds: d.getUTCSeconds(),
    milliseconds: d.getUTCMilliseconds(),
  };
  return (
    <p>{`${seconds}.${milliseconds}`}</p>
  );
};

Countdown.contextTypes = {
  remaining: PropTypes.number,
};

<Timer remaining={20000}>
  <Countdown />
</Timer>

could become something like this:

const Countdown = ({remaining}) => {
  const d = new Date(remaining);
  const { seconds, milliseconds } = {
    seconds: d.getUTCSeconds(),
    milliseconds: d.getUTCMilliseconds(),
  };
  return (
    <p>{`${seconds}.${milliseconds}`}</p>
  );
}

<Timer remaining={20000}>
  {remaining => <Countdown remaining={remaining} />}
</Timer>

This is a pattern also used by react-motion for example and what appeals to me personally is, that the data flow is a bit more explicit this way IMHO. (Of course there are a lot of differing opinions on this one, but in case you deem it useful ...)

@rmoorman rmoorman changed the title FAAC maybe worth considering instead of context types FaCC maybe worth considering instead of context types Nov 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant