storyblok / react-next-boilerplate

Nextjs Storyblok boilerplate
https://www.storyblok.com/tp/add-a-headless-cms-to-next-js-in-5-minutes
64 stars 34 forks source link

only changing state if in enterEditmode #17

Open chrillep opened 3 years ago

chrillep commented 3 years ago

the returned story will always be the first originalStory use in useState(originalStory) ?

initialState is never overwritten.

export function useStoryblok(originalStory, preview, locale) {
  const [story, setStory] = useState(originalStory)

and the state is only changed if we are in preview mode as initEventListeners runs setStory

useEffect(() => {
  // only load inside preview mode
  if (preview) {
    // first load the bridge, then initialize the event listeners
    addBridge(initEventListeners)
  }
}, [])

if (data.story) {
  setStory(data.story)
}

add a useEffect to update story to originalStory?

useEffect(() => {
  setStory(originalStory)
}, [originalStory])