Function withRenames

  • Make your component receive new props by renaming them.

    Type Parameters

    • const Map extends Record<string, string>

    Parameters

    • map: Map

      Example

      function Box({ handleClick, handleHover }: { handleClick: () => void; handleHover: () => void }) {
      ...
      }
      const NewBox = withRenames({
      onClick: "handleClick",
      onMouseOver: "handleHover"
      // ↑ oldProps goes to right
      // ↑ newProps goes to left
      })(Box);
      <NewBox onClick={() => {}} onMouseOver={() => {}} />
      // is equivalent to
      <Box handleClick={() => {}} handleHover={() => {}} />

    Returns Hoc<[WithRenamesFn<ToSchema<Map>>]>

    See

    withRename

    Example

    function Box({ handleClick, handleHover }: { handleClick: () => void; handleHover: () => void }) {
    ...
    }
    const NewBox = withRenames({
    onClick: "handleClick",
    onMouseOver: "handleHover"
    // ↑ oldProps goes to right
    // ↑ newProps goes to left
    })(Box);
    <NewBox onClick={() => {}} onMouseOver={() => {}} />
    // is equivalent to
    <Box handleClick={() => {}} handleHover={() => {}} />

Generated using TypeDoc