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

Can't have two TagInputs on screen #897

Open
biscoe916 opened this issue Jan 7, 2023 · 3 comments
Open

Can't have two TagInputs on screen #897

biscoe916 opened this issue Jan 7, 2023 · 3 comments
Labels

Comments

@biscoe916
Copy link

If you attempt to have two tagInputs on the screen, you get an error saying one can't have two html5 backends.

I do not want drag and drop functionality, so if I specify drag and drop should be turned off, it really shouldn't use react-dnd for anything.

@hannesgruber
Copy link

Having the same issue. Have a workaround for this been found? Or can it be fixed in a short amount of time?

@dnhuan
Copy link

dnhuan commented Apr 13, 2023

Found a solution! This would resolve the error cannot have two html5 backends at the same time

@hannesgruber @biscoe916 Wrap your <App/> around DndProvider and use import { WithOutContext as ReactTags } from "react-tag-input" instead. Here is my package.json

"react-dnd": "14.0.2",
"react-dnd-html5-backend": "14.0.2",
"react-tag-input": "6.8.1"

index.js

import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import { HTML5Backend } from "react-dnd-html5-backend";
import { DndProvider } from "react-dnd";

const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
  <DndProvider backend={HTML5Backend} context={window}>
    <App />
  </DndProvider>
);

then use this in your components

import { WithOutContext as ReactTags } from "react-tag-input";

you'll probably don't need context={window}, but the API may change in later versions, so I'll just keep it.

See react-dnd/react-dnd#3178 and react-dnd/react-dnd#3257

@xzhuah
Copy link

xzhuah commented Apr 8, 2024

Encountered this bug today, this bug goes away when I remove <React.StrictMode>, but I am not sure if there are any side effect.

I also tried wrapping App with DndProvider, but that doesn't make it work under StrictMode.

@ad1992 ad1992 added the bug label Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants