Last active
August 24, 2022 15:57
-
-
Save trezy/5dd6be419201efd613bcd7657df4602b to your computer and use it in GitHub Desktop.
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 { store } from './store.js' | |
function gameLoop() { | |
if (!store.getState().isPaused) { | |
// render game elements | |
} | |
requestAnimationFrame(gameLoop) | |
} | |
gameLoop() |
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 { useStore } from './useStore.js' | |
export function GameUI() { | |
const { | |
isPaused, | |
pause, | |
play, | |
} = useStore(state => ({ | |
isPaused: state.isPaused, | |
pause: state.pause, | |
play: state.play, | |
})) | |
return ( | |
<div className={'menu'}> | |
<button onClick={pause}> | |
{'Pause'} | |
</button> | |
</div> | |
) | |
} |
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 create from 'zustand/vanilla' | |
export const store = create((set, get) => ({ | |
isPaused: false, | |
pause() { | |
set({ isPaused: true }) | |
}, | |
play() { | |
set({ isPaused: false }) | |
}, | |
}) |
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 create from 'zustand' | |
import { store } from './store.js' | |
export const useStore = create(store) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment