Skip to content
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

Why model prop is passed to original view component? #8

Open
7iomka opened this issue Feb 24, 2023 · 4 comments
Open

Why model prop is passed to original view component? #8

7iomka opened this issue Feb 24, 2023 · 4 comments

Comments

@7iomka
Copy link

7iomka commented Feb 24, 2023

Hi. Why model prop is passed to original view component?
This is needed only for types?
Because I wasn't expected to receive it alongside with my component props.

const FeatureComponentSelect = modelView(factory, (props: SelectProps) => { const model = factory.useModel(); // some code inside return <Select {...props} /> })

So in the DOM I have model prop passed.
So this is a problem, and I need somehow to make 2 steps to solve this issue

  1. every type of component wrapper I need to mix to something like this
    props: SelectProps & { model: ReturnType<typeof factory.useModel> }
  2. if component passed rest props with spread, every time you need to extract model prop from it

So, my question is - why you pass model prop to original component if you never use it (model is always is extracted through factory.useModel hook)

My suggestion is to separate viewProps from model like this

 const { model, ...viewProps } = props;
@mistical2008
Copy link

It is useful in cases where you don't have children components but you want to create reusable feature. Created view has "model" field in it's props signature. Reading types is better than expecting.

@SQReder
Copy link

SQReder commented Dec 27, 2023

99% of components in our projects use model directly from props
And just like 2-3 times I was needed to use useModel hook to get model in child components

@7iomka
Copy link
Author

7iomka commented Dec 27, 2023

99% of components in our projects use model directly from props And just like 2-3 times I was needed to use useModel hook to get model in child components

This means that you need to add type of model in component props in 99% cases?

@SQReder
Copy link

SQReder commented Mar 5, 2024

99% of components in our projects use model directly from props And just like 2-3 times I was needed to use useModel hook to get model in child components

This means that you need to add type of model in component props in 99% cases?

I think it's kinda cheap

type Props = {
    model: Model<typeof myCoolModelFactory>
    otherProp: unknown
}

const MyCoolView = modelView(myCoolModelFactory, ({model, otherProp}: Props) =>{
    return null;
})

Is you haven't any extra props, so better

const MyCoolView = modelView(myCoolModelFactory, ({model}) =>{
    return null;
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants