Skip to content

Commit

Permalink
chore: add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Qun committed Jun 16, 2024
1 parent 703645a commit b6a5f4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions examples/ssr/simple-ssr-demo/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import renderer from './renderer'

const app = new Koa()

// 提供静态文件服务
app.use(serve(path.resolve(__dirname, '../client')))

// 处理 SSR 渲染
app.use(renderer)

app.listen(3000, () => {
Expand Down
8 changes: 4 additions & 4 deletions examples/ssr/ssr-zustand/client/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { createContext, useRef, useContext } from 'react'
import { useStore } from 'zustand'
import { createStore } from 'zustand/vanilla'

// export const useStore = create((set) => ({
// todo: null,
// }))

// 创建 Store
export const createTodoStore = (todo) => {
return createStore()((set) => ({
todo,
}))
}

// 创建 React Context,用来分发 Store
export const TodoStoreContext = createContext(undefined)

// 需要将这个 Provider 包裹在组件外面用来创建 Store、填充数据
export const TodoStoreProvider = ({ children, todo }) => {
const storeRef = useRef()
if (!storeRef.current) {
Expand All @@ -27,6 +26,7 @@ export const TodoStoreProvider = ({ children, todo }) => {
)
}

// 在组件中使用该 Hook
export const useTodoStore = (selector) => {
const todoStoreContext = useContext(TodoStoreContext)

Expand Down

0 comments on commit b6a5f4c

Please sign in to comment.