- Separation of responsibilities
- Loose Coupling
- Scalability
https://react-composition-sample.vercel.app/
yarn install
yarn dev
BottomSheet.tsx
- BottomSheet
- BottomSheet.Dimmed
- BottomSheet.Paper
- BottomSheet.Header
- BottomSheet.Body
- BottomSheet.Actions
bottomSheetState.ts
- element
- options
useBottomSheet.tsx
set bottom sheet state.
- open
- close
BottomSheetLayer.tsx
effected by state.
<BottomSheet>
<BottomSheet.Dimmed />
<BottomSheet.Paper>
{state.element}
</BottomSheet.Paper>
</BottomSheet>
open bottom sheet.
use hook(set element).
const { open } = useBottomSheet();
open(
<>
<BottomSheet.Header title="Caution" />
<BottomSheet.Body>Hello</BottomSheet.Body>
<BottomSheet.Actions><button>Primary</button></BottomSheet.Actions>
</>
);