This file contains hidden or 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
// _app.js | |
function MyApp({ Component, pageProps }) { | |
const preloadedState = pageProps | |
// Initial server-side and client side initial render | |
const [store] = useState(() => { | |
return initStore(preloadedState) | |
}) | |
// Handle server-side props passed in when switching pages | |
useEffect(() => { |
This file contains hidden or 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
// _app.js | |
function MyApp({ Component, pageProps }) { | |
const preloadedState = pageProps | |
// Initial server-side and client side initial render | |
const [store] = useState(() => { | |
return initStore(preloadedState) | |
}) | |
return ( | |
<Provider store={store}> |
This file contains hidden or 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
// pages/jobs.js | |
import Jobs from '../components/Jobs' | |
export default Jobs | |
// components/Jobs.js | |
import { addJob, removeJob } from '../data/jobs' | |
const Jobs = () => { | |
return <></> | |
} | |
const mapStateToProps = (state) => { |
This file contains hidden or 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
// createStore.js | |
const reducer = combine(reducerRegistry.getReducers()) | |
const store = createStore(reducer) | |
reducerRegistry.setChangeListener(reducers => { | |
store.replaceReducer(combine(reducers)) | |
}) | |
// data/jobs.js | |
export default function reducer(state = initialState, action = {}) { |
This file contains hidden or 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
// createStore.js | |
import jobs from 'reducers/jobs' | |
import books from 'reducers/books' | |
const reducers = { | |
jobs, | |
books | |
} | |
const store = createStore(combineReducers(reducers)) |