import React, { useContext, createContext } from 'react'; import { useEffect, useRef, useState } from '@storybook/client-api'; const Consumer = () => { // testing hooks in the component itself, // rendering JSX for the component without decorators // per https://github.com/storybookjs/storybook/pull/14652/ const value = useContext(DummyContext); return
value: {value}
; }; export default { title: 'Core/Hooks', component: Consumer, }; export const Checkbox = () => { const [on, setOn] = useState(false); return ( ); }; export const Input = () => { const [text, setText] = useState('foo'); return setText(e.target.value)} />; }; export const Effect = () => { const ref = useRef(); useEffect(() => { if (ref.current != null) { ref.current.style.backgroundColor = 'yellow'; } }); return ( ); }; export const ReactHookCheckbox = () => { const [on, setOn] = React.useState(false); return ( ); }; const DummyContext = createContext({}); export const Context = (args) => { // testing hooks in the story const storyContext = useContext(DummyContext); return ; }; Context.decorators = [ (Story) => ( ), ];