-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#36 react hook
- Loading branch information
Showing
16 changed files
with
163 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ language: node_js | |
|
||
node_js: | ||
- 8 | ||
- 6 | ||
|
||
install: | ||
- yarn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React/* , { useEffect } */ from 'react'; | ||
import { useRedux } from '../../hooks/useRedux'; | ||
import useDummy from '../../hooks/useDummy'; | ||
|
||
import style from './style.scss'; // eslint-disable-line no-unused-vars | ||
|
||
export default function FormPostTotalCount() { | ||
const [state] = useRedux(); | ||
const [dummyTimes, triggerDummy] = useDummy(); | ||
|
||
return ( | ||
<div styleName="style.posts__total"> | ||
<small styleName="style.posts__small"> | ||
this component uses react hook | ||
</small> | ||
<div> | ||
Total | ||
{state.pages.home.posts.length} | ||
Posts | ||
</div> | ||
<div styleName="style.posts__dummy"> | ||
{dummyTimes} | ||
times dummy | ||
</div> | ||
<button type="button" onClick={triggerDummy}> | ||
Dispatch Dummy | ||
</button> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { useRedux } from './useRedux'; | ||
import { dummy as dummyAction } from '../actions'; | ||
|
||
export default function useDummy() { | ||
const [state, dispatch] = useRedux(); | ||
const triggerDummy = () => { | ||
dispatch(dummyAction()); | ||
}; | ||
return [state.pages.home.howManyDummies, triggerDummy]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// react is very likely to provide an official hook for redux | ||
// https://reactjs.org/docs/hooks-faq.html#what-do-hooks-mean-for-popular-apis-like-redux-connect-and-react-router | ||
import { useContext } from 'react'; | ||
import { ReactReduxContext } from 'react-redux'; | ||
|
||
export function useRedux() { | ||
const { storeState: state, store: { dispatch } } = useContext(ReactReduxContext); | ||
return [state, dispatch]; | ||
} | ||
|
||
export default useRedux; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.