Is there a way without using Redux with which I can from my home.js page (I'm using hooks not classes) set/use a state, pass it to my component MyComponent.js and once a div is clicked inside this component update the state (so for the home.js page as well)?
In home.js I have something like:
export default function Page({ session, items }) {
const [selectedTab, setSelectedTab] = useState('main')
const handleSelect = (e) => {
setSelectedTab(e);
}
... // then I return some react-bootstrap tabs, where Tab.Container is like:
<Tab.Container id="tabs-home" activeKey={selectedTab} onSelect={(e) => handleSelect(e)}>
...
}
In MyComponent.js I tried:
export default function MyComponent(props) {
const [selectedTab, setSelectedTab] = useState()
const handleClick = () => {
setSelectedTab("second");
}
... // and I return something like:
<div onClick={() => handleClick()} style={{cursor: 'pointer'}}>blahblah</div>
So basically when clicking on the item inside the component I need to change selected tab in the page. I'll then need to pass props as well from the component back to the page, but once I understand how I can pass state I guess is the same process again
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…