-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add the example for useContext #127
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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 {} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's awesome, thanks!
@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 Then please inject in README_SOURCE all the 3 related context examples and the list would go like this: - ThemeContext- ThemeProvider- ThemeConsumer
|
@piotrwitek I fixed according to your reviews! please confirm!:pray: I have understood how you are thinking about examples for Context API. |
@sosukesuzuki Yeah sure sounds good to me 👍 and great job! |
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`.
resolve #120 (comment)
playground/src/context/theme-provider.tsx
totheme-provider.tsx
,theme-consumer.tsx
andtheme-context.ts
.useContext
toplayground/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.