Best Practices for Passing Props Through Context #5269
-
Hello guys, I have a Separator in a Menu and want to pass some props through the context. Still, Menu also provides props via context and overwrites my props, so I created a Separator component with its context that forwards all props to the base component. I would like to know if this is the best way or if you have any suggestions. Thank you so much. import {createContext, forwardRef} from 'react'
import {
Separator as RACSeparator,
useContextProps,
type ContextValue,
type SeparatorProps,
} from 'react-aria-components'
export const SeparatorContext =
createContext<ContextValue<SeparatorProps, HTMLElement>>(null)
export const Separator = forwardRef<HTMLElement, SeparatorProps>(
function Separator(_props, _ref) {
const [props, ref] = useContextProps(_props, _ref, SeparatorContext)
return <RACSeparator {...props} ref={ref} />
},
) |
Beta Was this translation helpful? Give feedback.
Answered by
snowystinger
Oct 19, 2023
Replies: 1 comment 1 reply
-
Is this different than your previous question? #5046 (comment) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
hosmelq
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this different than your previous question? #5046 (comment)