wix-incubator / autoviews

A library for building user interfaces with JSON schemas, react components and data
MIT License
12 stars 4 forks source link

Change AutoItems interface #58

Open yoavaa opened 2 years ago

yoavaa commented 2 years ago

Is there an existing issue for this?

The problem

AutoItems props are defined as

export type AutoItemsProps = {
    render?(
        item: React.ReactNode,
        props: AutoViewProps,
        index: number
    ): React.ReactNode;
} & AutoViewProps;

which forces to provide render as a prop in JSX, as

<AutoItems {...props} render={
    (node) => <li>node</li>
}>
</AutoItems>

Describe the solution you'd like

I suggest to change the interface a bit, renaming render to children, so that

export interface AutoItemsProps extends AutoViewProps {
    render?(
        item: React.ReactNode,
        props: AutoViewProps,
        index: number
    ): React.ReactNode;
}

which allows

<AutoItems {...props}>
    {(node) => <li>node</li>}
</AutoItems>

and still allows using

<AutoItems {...props}/>

Basically, using a property named children allows to place the function as a child in the JSX

Describe alternatives you've considered

No response

yoavaa commented 2 years ago

Same issue for AutoFields