Skip to content
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

Fix TypeError: Cannot read properties of undefined (reading '__H') #1

Open
wants to merge 1 commit into
base: jeffreyatw/react-redux
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"react": "npm:@preact/compat@*",
"react-dom": "npm:@preact/compat@*",
"react-redux": "^8.1.3",
"redux": "^4.2.1",
"vike": "0.4.143",
"vite": "^4.0.3"
},
Expand Down
10 changes: 9 additions & 1 deletion renderer/PageShell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import logo from './logo.svg'
import { PageContextProvider } from './usePageContext'
import './PageShell.css'
import { Link } from './Link'

import { Provider } from 'react-redux'
import { getStore } from './store'

export { PageShell }

const PageShell = function ({ children, pageContext }) {
// NOTE(aurelien): actually initializing the store here is probably not a good idea as it has to be done in different
// ways whether we are on client or on server. So probably this should be moved to +onRenderHtml.jsx and
// +onRenderClient.jsx . See also:
// * https://github.com/brillout/vike-with-redux/blob/main/renderer/%2BonRenderClient.jsx
// * https://redux.js.org/usage/server-rendering
const store = getStore({})
return (
<Provider>
<Provider store={store}>
<PageContextProvider pageContext={pageContext}>
<Layout>
<Sidebar>
Expand Down
21 changes: 21 additions & 0 deletions renderer/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copy-pasted from https://github.com/brillout/vike-with-redux/blob/main/renderer/store.js

import { createStore } from 'redux'

export { getStore }

function getStore(PRELOADED_STATE) {
const store = createStore(counterReducer, PRELOADED_STATE)
return store
}

function counterReducer(state = { value: 0 }, action) {
switch (action.type) {
case 'counter/incremented':
return { value: state.value + 1 }
case 'counter/decremented':
return { value: state.value - 1 }
default:
return state
}
}
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = {
include: ['preact/devtools', 'preact/debug', 'preact/jsx-dev-runtime', 'preact', 'preact/hooks'],
},
ssr: {
noExternal: ['react-redux/*', 'use-sync-external-store/*']
noExternal: ['react-redux']
}
}

Expand Down