-
Notifications
You must be signed in to change notification settings - Fork 7
Conversation
7a1bc0e
to
037989c
Compare
Interesting discussion about context re-render: And cool article to check re-render with context: |
I'm having difficulties seeing how this will be used. For example the // Button.tsx
class Button extends PureComponent<P, S> {
// ...
}
// index.tsx
const StyledButton = styled(Button)`
/* [...] */
` So in order to use the hook we need to transform the // Button.tsx
function Button({ className }) {
const { focusVisible, onFocus, onBlur } = useFocusVisible()
// ...
// Simplified for the example
return (
<button
onFocus={onFocus}
onBlur={onBlur}
className={cc([className, prefix({ focusVisible })])}
/>
)
}
// index.tsx
const StyledButton = styled(Button)`
/* ... */
&.kirk-focusVisible {
/* ... */
}
` Is that right? |
523d68f
to
dc1efe7
Compare
} | ||
|
||
export const FocusVisibleContext = createContext({ | ||
hadKeyboardEvent: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setted to false
as initial value cause not the common behavior.
1187e97
to
498b6a4
Compare
Yes it'll be used this way + having the FocusVisibleProvider as wrapper like we do with MediaSizeProvider |
047426a
to
764552c
Compare
764552c
to
b1c1532
Compare
ca5e5cf
to
4851f21
Compare
src/_utils/focusVisible/index.tsx
Outdated
|
||
export const FocusVisibleContext = createContext(false) | ||
|
||
export const FocusVisibleProvider = (props: PropsWithChildren<{}>) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@simonrelet I use PropsWithChildren
as type for children instead of interface like:
interface FocusVisibleProviderProps {
children: ReactNode
}
Not typescript expert so just want to know if it's the right way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have rarely seen PropsWithChildren
before, but I don't feel comfortable having a component with props but no exported prop types.
If we really want to avoid the children?: React.ReactNode
part maybe we can write:
export type FocusVisibleProviderProps = PropsWithChildren<{}>
But the empty type (<{}>
) still feels weird.
Having the extended type declaration (children?: React.ReactNode
) wouldn't bother me much.
Not sure my comment helps here 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really have strong opinion for this point so I'll fallback with:
type FocusVisibleProviderProps = {
children: ReactNode
}
7ca450c
to
65c1608
Compare
1aa8730
to
3b42dc0
Compare
e700f37
to
ea2481b
Compare
7dbe8a5
to
08bbbe8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work 👍
Could you "illustrate" this PR? Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice refactor! Great improvement on code readability 🦉
08bbbe8
to
1188f7c
Compare
1188f7c
to
65855ff
Compare
No description provided.