overmind/
: Group overmind stuffeffects/
: Side effectsrouter.js
: Router side effectgql.js
: GraphQL side effect
actions.js
: Actions, you may want to split them into logical groupsstate.js
: The state object
index.js
: Export state, actions, effects and hooks
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
"use client"; | |
import useInterval from "use-interval"; | |
import { useRouter } from "next/navigation"; | |
export function AutoReload({ delay = 1000 }) { | |
const router = useRouter(); | |
useInterval(() => { | |
router.refresh(); |
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
"use client"; | |
import { useForm } from "react-hook-form"; | |
import { zodResolver } from "@hookform/resolvers/zod"; | |
import { Form } from "@/components/ui/form"; | |
import { Button } from "@/components/ui/button"; | |
import * as z from "zod"; | |
import { useFormAction } from "@/lib/useFormAction"; | |
export function PostForm() { |
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
import { useState, useLayoutEffect, useCallback } from "react"; | |
import { flushSync } from "react-dom"; | |
const useDynamicMinHeight = (ref) => { | |
const [minHeight, setMinHeight] = useState(0); | |
const updateMinHeight = useCallback(() => { | |
if (ref.current) { | |
flushSync(() => { | |
setMinHeight(0); |
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
import React from 'react'; | |
import { useAppState, useActions } from '~/overmind'; | |
export default function Post() { | |
const { post } = useAppState(); | |
const { myAction } = useActions(); | |
return ( | |
<div> | |
<h1>{ post.title }</h1> |
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
import { derived } from 'overmind'; | |
export const state = { | |
loading: false, | |
auth: {}, | |
router: {}, | |
post: null, | |
isAuthenticated: derived(state => state.auth.token !== undefined) | |
}; |
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
export const showPostPage = async ({ state, actions, effects }, params) => { | |
if (!state.auth.token) { | |
effects.router.open('/'); | |
} | |
state.router = { page: 'post', params }; | |
await actions.loadPost({ id: params.id }); | |
}; |
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
export const onInitializeOvermind = ({ state, actions, effects }, instance) => { | |
state.auth.token = effects.auth.getLocalStorageToken(); | |
effects.router.initialize({ | |
'/': actions.showLoginPage, | |
'/:postId': actions.showPostPage | |
}); | |
} |
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
import page from 'page'; | |
export const router = { | |
initialize(routes) { | |
Object.keys(routes).forEach(url => { | |
page(url, ({ params }) => routes[url](params)); | |
}); | |
page.start(); | |
}, | |
open: url => page.show(url) |
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
import { createOvermind } from 'overmind'; | |
import { | |
createStateHook, | |
createActionsHook, | |
createEffectsHook, | |
createReactionHook | |
} from 'overmind-react'; | |
import { state } from './state'; | |
import * as actions from './actions'; | |
import { gql } from './effects/gql'; |
NewerOlder