Skip to content

Instantly share code, notes, and snippets.

@rhernandog
Last active December 17, 2020 14:53
Show Gist options
  • Save rhernandog/5bcc68558b62cf034aada402a5161980 to your computer and use it in GitHub Desktop.
Save rhernandog/5bcc68558b62cf034aada402a5161980 to your computer and use it in GitHub Desktop.
React & Recompose withProps - A simple example of using recompose's withProps
// styles for this are based on Bootstrap 3.3.7
import React, { Component } from "react";
import ReactDOM from "react-dom";
import { withProps } from "recompose";
const users = [
{ "name": "Homer Jay", "status": "pending" },
{ "name": "El Barto", "status": "active" },
{ "name": "SideshowBob", "status": "active" }
];
const User = ({ name, status, button }) =>
<div className={"panel panel-" + (status==="active" ? "primary" : "warning")}>
<div className="panel-body">
This user is {name}
{
button ? (<span> - <button className="btn btn-primary">Click</button></span>) : null
}
</div>
</div>
;
const Another = withProps({"button":true })(User);
const renderUsers = (e,i) => {
const props = {name:e.name, key:e.name, status:e.status};
return e.status === "active" ? <Another {...props} /> : <User {...props} />;
};
const App = () =>
<div className="container">
<div className="row">
<div className="col-xs-12">
<h2 className="text-center">App</h2>
{ users.map(renderUsers ) }
</div>
</div>
</div>
;
ReactDOM.render(
<App />, document.getElementById("app-wrap")
)
@jhorgint
Copy link

jhorgint commented Jan 9, 2018

thanks for sharing

@develomark
Copy link

Thank you

@emision
Copy link

emision commented Feb 28, 2018

Nice example. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment