KEMBAR78
React App with DnD and Screens | PDF
0% found this document useful (0 votes)
24 views1 page

React App with DnD and Screens

notes

Uploaded by

jishika491
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

React App with DnD and Screens

notes

Uploaded by

jishika491
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

app.

js

import React, { useState } from "react";


import "./App.css"; // Global styles
import MainScreen from "./components/MainScreen";
import CommandScreen from "./components/CommandScreen";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";

function App() {
const [currentScreen, setCurrentScreen] = useState("main");
const [catActions, setCatActions] = useState([]);
const [ratActions, setRatActions] = useState([]);

const handleDoneForCat = (actions) => {


setCatActions(actions); // Store actions for the cat
setCurrentScreen("main");
};

const handleDoneForRat = (actions) => {


setRatActions(actions); // Store actions for the rat
setCurrentScreen("main");
};

return (
<DndProvider backend={HTML5Backend}>
<div>
{currentScreen === "main" ? (
<MainScreen
onAddActionForCat={() => setCurrentScreen("commands-cat")}
onAddActionForRat={() => setCurrentScreen("commands-rat")}
catActions={catActions}
ratActions={ratActions}
setCatActions={setCatActions}
setRatActions={setRatActions} // Pass down both setCatActions and
setRatActions
/>
) : currentScreen === "commands-cat" ? (
<CommandScreen
onBack={() => setCurrentScreen("main")}
onDone={handleDoneForCat}
/>
) : (
<CommandScreen
onBack={() => setCurrentScreen("main")}
onDone={handleDoneForRat}
/>
)}
</div>
</DndProvider>
);
}

export default App;

You might also like