-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
148 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import {useDispatch, useSelector, useStore} from 'react-redux'; | ||
import Link from 'next/link'; | ||
import {NextPage} from 'next'; | ||
import {fetchGipp, selectGippPageData, selectGippPageStateTimestamp, selectGippPageTestData, wrapper} from '../store'; | ||
|
||
const Page: NextPage = () => { | ||
console.log('State on render', useStore().getState()); | ||
const dispatch = useDispatch(); | ||
const testData = useSelector(selectGippPageTestData); | ||
const stateTimestamp = useSelector(selectGippPageStateTimestamp); | ||
const data = useSelector(selectGippPageData); | ||
|
||
console[testData ? 'info' : 'warn']('Rendered testData: ', testData); | ||
|
||
if (!testData || !data) { | ||
throw new Error('Whoops! We do not have the data and testData selector data!'); | ||
} | ||
|
||
return ( | ||
<> | ||
<div style={{backgroundColor: 'lavender', padding: '20px'}}>Timestamp in state: {stateTimestamp}</div> | ||
<div className={`page${1}`}> | ||
<h3>{testData}</h3> | ||
<Link href="/subject/1">Go id=1</Link> | ||
| ||
<Link href="/subject/2">Go id=2</Link> | ||
| ||
<Link href="/detail/1">Go to details id=1</Link> | ||
| ||
<Link href="/detail/2">Go to details id=2</Link> | ||
| ||
<Link href="/pokemon/pikachu">Go to Pokemon</Link> | ||
| ||
<Link href="/">Go to homepage</Link> | ||
</div> | ||
<button onClick={() => dispatch(fetchGipp())}>Refresh timestamp</button> | ||
</> | ||
); | ||
}; | ||
|
||
Page.getInitialProps = wrapper.getInitialPageProps(store => async () => { | ||
await store.dispatch(fetchGipp()); | ||
return {}; | ||
}); | ||
|
||
export default Page; |
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