Function withRename

  • Make your component receive a new prop by renaming it.

    Type Parameters

    • const NewProp extends string

    • const OldProp extends string

    Parameters

    • newProp: NewProp

      Example

      function Box({ handleClick }: { handleClick: () => void }) {
      ...
      }
      const NewBox = withRename("onClick", "handleClick")(Box);
      // ↑ this will be the property
      <NewBox onClick={() => {}} />
      // ↑ onClick is the new prop
      // is equivalent to
      <Box handleClick={() => {}} />
    • oldProp: OldProp

      Example

      function Box({ handleClick }: { handleClick: () => void }) {
      ...
      }
      const NewBox = withRename("onClick", "handleClick")(Box);
      // ↑ this is the old prop
      <NewBox onClick={() => {}} />
      // is equivalent to
      <Box handleClick={() => {}} />
      // ↑ this is the old prop

    Returns Hoc<[WithRenameFn<NewProp, OldProp>]>

    See

    withRenames

    Example

    function Box({ handleClick }: { handleClick: () => void }) {
    ...
    }
    const NewBox = withRename("onClick", "handleClick")(Box);
    <NewBox onClick={() => {}} />
    // is equivalent to
    <Box handleClick={() => {}} />

Generated using TypeDoc