Giter VIP home page Giter VIP logo

Comments (2)

levino avatar levino commented on August 16, 2024

Here is my solution with Ramda:

const mapPropsWithChildren = R.partial(
  R.pipe(R.pipe(R.converge, R.unapply)(R.merge), mapProps),
  [R.pick(['children'])],
)

from recompose.

levino avatar levino commented on August 16, 2024

Okay I think I got the answer.

So lets say you have an App like this:

import * as React from "react";
import { mapProps } from "recompose";
import * as R from "ramda";

const Box = (props: any) => <div {...props} />;

const Alert = mapProps(
  R.applySpec({
    style: {
      backgroundColor: R.ifElse(
        R.propEq("type", "danger"),
        R.always("red"),
        R.always("blue")
      ),
      height: R.always("200px"),
      margin: R.always("20px")
    },
    children: R.prop("children")
  })
)(Box);

const NonFunctionalAlert = ({ type, children }: any) => (
  <div
    style={{
      backgroundColor: type === "danger" ? "red" : "blue",
      margin: "20px",
      height: "200px"
    }}
  >
    {children}
  </div>
);

export default () => (
  <div>
    <Alert type={"danger"}>Danger</Alert>
    <NonFunctionalAlert type={"info"}>Info</NonFunctionalAlert>
  </div>
);

The components Alert and NonFunctionalAlert are the same. You can see that in the NonFunctionalAlert you also have to pass the children property to the Box component, even though in my example I am using the syntactical sugar provided by JSX instead of setting the prop explicitly. I still cannot omit the "picking up and shoving on" of the children. So the same holds for my nice component using mapProps. If I would just spread all the props from NonFunctionalAlert into Box then I could "omit" the children but then I would also just have implement withProps instead of mapProps.

from recompose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.