Skip to content

Latest commit

 

History

History
55 lines (45 loc) · 1.23 KB

toggle.mdx

File metadata and controls

55 lines (45 loc) · 1.23 KB

import { State, Observe } from '../es'; import Table from './helpers/table';

Toggle

An example using React components for a table layout and a button to toggle a boolean state

Which Car Should You Buy?

There a number of factors to consider when buying a car.

Use our special formula to help you decide!

<State initialState={{ vehicles: [ { name: "Volvo", price: 29000, reliability: 7 }, { name: "Honda", price: 25000, reliability: 8 }, ], revealChoice: false, }}

{({vehicles}) => ( Object.values(v))]} /> )}

Which should you buy?

{ ({vehicles, revealChoice, setState}) => { const mostReliable = [...vehicles] .sort((a, b) => b.reliability - a.reliability)[0]; const handleClick = e => { e.preventDefault(); setState(s => ({ ...s, revealChoice: !s.revealChoice })); } return (
Reveal Choice { revealChoice &&
You should buy the {mostReliable.name} because it is the most reliable
}
); } }