Skip to content

Discussion on Spread PropsΒ #637

@jacobp100

Description

@jacobp100

I wanted to open a discussion on a possible way forward to add spread props

If we required users to specify the type of the spread props (assume in the same file for now), it might be possible to have the PPX transform the following,

type exampleSpeadProps = {
  someProp: string,
  someOtherProp: string,
}

[@react.component]
let example = (~someComponentProp, [@react.rest] exampleSpreadProps) =>
  <div
    someComponentProp
    [@react.spead] exampleSpreadProps
  />

into

[@react.component]
let example = (~someComponentProp, ~someProp: string, ~someOtherProp: string) =>
  <div
    someComponentProp
    someProp
    someOtherProp
  />

This should preserve type safety and enable spreading

It'll also have the added benefit that you could use multiple rest/spread types (assuming no names overlap), and spread them to different child elements

It might also be possible to define the types in a different file if we leveraged some of the code from ppx-import

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCppxissues related to the reason-react ppx

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions