useToggle
Toggle a boolean value on or off with handlers
const [state, setOn, setOff, toggle] = useToggle(initialState, handlers);
Sample Usage
Show editable code example
Any Paragon component or export may be added to the code example.
() => {const defaultIsOn = true;const handlers = {handleToggleOn: () => console.log('called handleToggleOn'),handleToggleOff: () => console.log('called handleToggleOff'),handleToggle: () => console.log('called handleToggle'),}const [isOn, setOn, setOff, toggle] = useToggle(defaultIsOn, handlers);return (<div><p>Toggle is{isOn? <Badge variant="success">On</Badge>: <Badge variant="light">Off</Badge>}</p><Button onClick={setOn} className="mr-2" variant="outline-primary">set on</Button><Button onClick={setOff} className="mr-2" variant="outline-primary">set off</Button><Button onClick={toggle} className="mr-2" variant="outline-primary">toggle</Button></div>);}
Basic Usage
Show editable code example
Any Paragon component or export may be added to the code example.
() => {const [isOpen, open, close] = useToggle(false);return (<Card style={{ width: '18rem' }}><Card.ImageCap src="https://picsum.photos/400/200/" srcAlt="Image description" /><Card.Header title="Card Title"/><Card.Section><p>Some quick example text to build on the card title and make up the bulk ofthe card's content.</p>{isOpen ? (<><p>Poutine cred portland heirloom seitan sartorial 90's cray. Humblebrag blue bottle venmo, cloud bread cronut neutra sartorial whatever slow-carb tattooed cliche helvetica poutine squid. Direct trade health goth gentrify kitsch, heirloom blog umami synth ennui seitan messenger bag. Literally poutine slow-carb, hexagon leggings seitan readymade.</p><Button block variant="outline-primary" onClick={close}>Close</Button></>) : (<Button block variant="outline-primary" onClick={open}>See more</Button>)}</Card.Section></Card>);}
Usage Insights#
useToggle
Project Name | Paragon Version | Instance Count | |
---|---|---|---|
frontend-app-account | 20.36.0 | 1 | |
frontend-app-admin-portal | 20.26.3 | 12 | |
frontend-app-authn | 20.36.2 | 2 | |
frontend-app-communications | 20.30.1 | 2 | |
frontend-app-discussions | 20.15.0 | 9 | |
frontend-app-enterprise-public-catalog | 20.29.0 | 1 | |
frontend-app-learner-dashboard | 20.32.0 | 3 | |
frontend-app-learner-portal-enterprise | 20.36.0 | 10 | |
frontend-app-learning | 20.28.4 | 1 | |
frontend-lib-special-exams | 20.22.4 | 4 | |
prospectus | 20.32.3 | 1 |