March 2019
Intermediate to advanced
534 pages
14h 52m
English
You can add a value property to the TabsContainer component so that you can set whichever tab to activate initially. For example, you might want the second tab to be active instead of the first tab when the screen first loads. To do this, you'll have to add a default property value for value, call setValue() if the value state hasn't been set yet, and remove value from the initial state:
function TabContainer({ children, value: valueProp }) { const [value, setValue] = useState(); const onChange = (e, value) => { setValue(value); }; if (value === undefined) { setValue(valueProp); } return ( <Fragment> <Tabs value={value} onChange={onChange}> {Children.map(children, child => ( <Tab label={child.props.label} /> ))} </Tabs> {Children.map(children, ...Read now
Unlock full access