const App = () => {
const [heading, setHeading] = useState("");
const [img, setImg] = useState("");
let [count, setCount] = useState(0);
console.log("Main",count)
const increment = () => {
if (count < Data.length-1) {
setCount(count + 1);
nextDiv();
} else {
setCount(0);
nextDiv();
}
};
const decrement = () => {
if (count > 0) {
setCount(count - 1);
preDiv();
} else {
setCount(Data.length-1);
preDiv()
}
};
const nextDiv = ()=>{
console.log("nextDiv",count)
}
const preDiv = ()=>{
console.log("PreDiv",count)
}
return (
<>
<div className="imgBox">
<Card head={heading} img={img} />;
</div>
<div className="btns">
<button onClick={increment}>Next</button>
<button onClick={decrement}>Previous</button>
</div>
</>
);
};
whenever i am incrementing it with button suppose main count is 1 then next Div count is 0 and so on and on decrement it is vice versa i want that my main_count and NextDiv count should be same when i change it throgh buttons