-
Notifications
You must be signed in to change notification settings - Fork 14
Convert all components to Hooks #766
Comments
Base branch for this issue: https://github.com/sociomantic-tsunami/nessie-ui/tree/Milestone-Hooks%21 |
Hey @daniel-martic-sociomantic, @mahmoud-zakria-sociomantic: I think we should use a custom hook for consuming the theme. I’m thinking something like this, it would be used in place of import ThemeProvider from '.....'
function useTheme( props )
{
const { displayName } = useTheme.caller; // `caller` is “nonstandard” JS... should we use it? 😈
const { [ displayName ] : theme } = useContext( ThemeProvider ); // check out ma fancy destructuring!
return props.cssMap || // cssMap prop overrides the theme, if defined
( typeof theme === 'function' ? theme( props ) : theme ); // if theme is a function, call it with the current props
} What do you think? |
Right now we have two big-ish problems:
|
@conor-cafferkey-sociomantic Why would we do it? what the problem with |
Absolutely no problem with The problem is having to write something like this in every component is error-prone:
In particular, the part where we have to specify the component name (here, |
And while we’re at it, we can do something similar when we generate a component
|
It’s time to hooks-ify all the things:
withDropdownwill be removedFor most components, this just means converting (back) to function components and using:
useContext
to consume the theme (all of the above components)useImperativeHandle
/forwardRef
to expose afocus()
function (for components that are focusable; remove any props likeinputRef
,buttonRef
, etc.)For stateful components:
useCallback
getDerivedStateFromProps
can be replaced withuseMemo
.The text was updated successfully, but these errors were encountered: