Skip to content

Add the example for useContext #127

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

Merged
merged 7 commits into from
Jan 26, 2019

Conversation

sosukesuzuki
Copy link
Contributor

resolve #120 (comment)

  • divide playground/src/context/theme-provider.tsx to theme-provider.tsx, theme-consumer.tsx and theme-context.ts.
  • add the example for useContext to playground/src/hooks/use-theme-context.tsx.

Do you have a reason that playground/src/context/theme-provider have not been add to README? If you don't have any reason, I think that we should add it to README.

Copy link
Owner

@piotrwitek piotrwitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Owner

@piotrwitek piotrwitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed some possible improvements.

interface State {
theme: Theme['theme'];
theme: Theme;
}
export class App extends React.Component<{}, State> {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to ThemeProvider

import * as React from 'react';
import ThemeContext from './theme-context';

interface ThemedButtonProps {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to refactor all the interface ThemedButtonProps to just type Props =. I prefer that now as it is more concise and cleaner, also has a benefit to do things like this:

type Props = typeof dispatchProps & ReturnType<typeof mapStateToProps>;

Please could you do it for all the components related to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I can:+1:

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's awesome, thanks!

@piotrwitek
Copy link
Owner

piotrwitek commented Jan 26, 2019

@sosukesuzuki regarding context, no reason, I was planning to add it eventually but just didn't have enough time to do that until now.

But it would be really great if you could add it as well as you have already done most of the work needed to finish it.

Now we just need to create a new sub-section in Component Typing Patterns between Redux Connected Components and Hooks.

Then please inject in README_SOURCE all the 3 related context examples and the list would go like this:

- ThemeContext

- ThemeProvider

- ThemeConsumer

In this example it would be great to put a link to the useContext example.

@sosukesuzuki
Copy link
Contributor Author

@piotrwitek I fixed according to your reviews! please confirm!:pray:

I have understood how you are thinking about examples for Context API.
I want to add examples for Context API. But, I want to create as another PR at after this PR is merged.

@piotrwitek piotrwitek merged commit 92c9a5c into piotrwitek:master Jan 26, 2019
@piotrwitek
Copy link
Owner

@sosukesuzuki Yeah sure sounds good to me 👍 and great job!
Just copy the implementation scope please into a new PR so we have the requirements there for reference. Thanks!

piotrwitek pushed a commit that referenced this pull request Feb 3, 2019
resolve #120 (comment)

- divide `playground/src/context/theme-provider.tsx` to `theme-provider.tsx`, `theme-consumer.tsx` and  `theme-context.ts`.
- add the example for `useContext` to `playground/src/hooks/use-theme-context.tsx`.
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

Successfully merging this pull request may close these issues.

Add examples for another hooks?
2 participants