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

How to use resetServerContext? #1533

Closed
revialim opened this issue Oct 5, 2019 · 3 comments
Closed

How to use resetServerContext? #1533

revialim opened this issue Oct 5, 2019 · 3 comments

Comments

@revialim
Copy link

revialim commented Oct 5, 2019

I currently ran into the problem, that causes my browser console to warn me with the following message, and weird behavior in my drag and drop. I load a list of objects dynamically and render these objects as draggable components.

Warning: Prop `data-react-beautiful-dnd-droppable` did not match. Server: "49" Client: "0"

I found this issue and would like to use resetServerContext to resolve my problem, but the documentation is very minimal. Is there an example how to apply it?

Currently I tried to use it before my get request in useEffect, but the warning still occurs.

useEffect(() => {
  resetServerContext(); 
  axios.get(...);
}, [])

What version of React are you using?

^16.8.4

What version of react-beautiful-dnd are you running?

^11.0.5

What browser are you using?

Chrome, Firefox

@Axedyson
Copy link

Axedyson commented Mar 6, 2020

How did you use it?

@rfire12
Copy link

rfire12 commented May 17, 2020

How did you use it?

You need to use resetServerContext if you're implementing server side rendering.
Call it right before renderToString in your client server.

https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/api/reset-server-context.md

@commanderz
Copy link

Another solution:

const [isBrowser, setIsBrowser] = useState(false);

useEffect(() => {
  setIsBrowser(process.browser);
}, [])

function Home() {
  return(
   <>
    {isBrowser ? <DragDropContext> { /* all rbd code */ } </DragDropContext> : null}
   </>
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants