-
-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot create a component with generic props with reatomComponent #850
Comments
It is imposible in TypeScript to to accept a generic and return it via other generic function. Unfortunatly you shuold cast the component type, like this: |
@MichailShcherbakov nice! We need to add this to our sources! |
@artalar I'm glad to hear that. I've created a PR with an example how it could be implemented. I've changed the props type inferring to provide more clear props type of components. In the PR example it will be: import { reatomComponent, PropsWithCtx } from "@reatom/npm-react";
interface ListProps<T> {
items: T[];
onItemClick: (item: T) => void;
}
// const List: <T>(props: ListProps<T>) => JSX.Element
const List = reatomComponent(<T,>({ ctx, items, onItemClick }: PropsWithCtx<ListProps<T>>) => {
return null;
}, 'List'); |
What happened?
The
reatomComponent
has next props type:I need to create a component with generic props as shown below:
But obviously
ctx
is not there.I tried to import
CtxRender
and put it in the props but@reatom/npm-react
doesn't export it.So it would be great if you add something like this (inspired by
React.PropsWithChildren
)or at least you should export
CtxRender
in@reatom/npm-react
Part
Package @reatom/npm-react
Version
3.8.6
What browsers are you seeing the problem on?
Microsoft Edge
Relevant log output
No response
The text was updated successfully, but these errors were encountered: