Skip to content

Instantly share code, notes, and snippets.

View thulioph's full-sized avatar
🔥

Thulio Philipe thulioph

🔥
View GitHub Profile
@thulioph
thulioph / ModalClass.js
Last active September 20, 2018 03:50
An example to demonstrate a Modal component using class.
import React from "react";
import { ModalComponent } from "./Modal";
class ModalContainer extends React.Component {
state = {
showModal: false
};
onHandleModal = () => {
@thulioph
thulioph / Modal.js
Last active September 20, 2018 03:49
An example to demonstrate a Modal component using Reactstrap
import React from "react";
import PropTypes from "prop-types";
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from "reactstrap";
export const ModalComponent = ({
showModal,
onHandleModal,
onBtnSuccess,
onBtnCancel,
mainBtnLabel,
@thulioph
thulioph / ModalHOC.js
Last active September 20, 2018 03:28
An example to demonstrate a Modal component made using Recompose
import React from "react";
import { compose, withState, withHandlers } from "recompose";
import { ModalComponent } from "./Modal";
const hoc = compose(
withState("showModal", "updateModal", false),
withHandlers({
onHandleModal: ({ updateModal, showModal }) => () => updateModal(!showModal),
onBtnSuccess: () => () => console.warn("Success"),
@thulioph
thulioph / mapProps.js
Created September 13, 2018 04:29
An example to demonstrate the mapProps API of Recompose
import React from 'react';
import { compose, withState, mapProps } from 'recompose';
const MyComponent = ({ myCounter, setCounter }) => (
<div>
<h1>{myCounter}</h1>
<button onClick={() => setCounter(myCounter + 1)}>Add</button>
<button onClick={() => setCounter(myCounter - 1)}>Remove</button>
</div>
);
@thulioph
thulioph / withHandlers.js
Created September 13, 2018 04:06
An example to demonstrate the withHandlers API of Recompose
import React from 'react';
import { compose, withState, withHandlers } from 'recompose';
const MyComponent = ({ counter, increment, decrement, reset }) => (
<div>
<h2>{counter}</h2>
<button onClick={increment}>Add</button>
<button onClick={decrement}>Remove</button>
<button onClick={reset}>Reset</button>
</div>
@thulioph
thulioph / nest.js
Last active September 13, 2018 03:54
An example to demonstrate the nest API of Recompose
import React from 'react';
import { nest } from 'recompose';
const Header = ({ children }) => (
<div>
<header>HEY!</header>
{children}
</div>
);
@thulioph
thulioph / branch.js
Last active September 13, 2018 03:52
An example to demonstrate the branch API of Recompose
import React from 'react';
import { branch } from 'recompose';
const MyComponent = () => <h2>Hello!</h2>;
const IsLessThanZero = BaseComponent => props => (
<div>
<BaseComponent {...props} />
<h1>Less or equal than zero!</h1>
</div>
@thulioph
thulioph / withState.js
Last active September 13, 2018 03:43
An example to demonstrate the withState API of Recompose
import React from 'react';
import { withState } from 'recompose';
const MyComponent = ({ counter, setCounter }) => (
<div>
<h1>{counter}</h1>
<button onClick={() => setCounter(counter + 1)}>Add</button>
<button onClick={() => setCounter(counter - 1)}>Remove</button>
</div>
);
@thulioph
thulioph / lifecycle.js
Last active September 11, 2018 03:22
An example to demonstrate the lifecycle API of Recompose
import React from 'react';
import { lifecycle } from 'recompose';
const MyComponent = ({ data }) => (
<div>{data}</div>
);
const MyComponentModified = lifecycle({
componentDidMount() {
doSomething().then(data => {