Archivo de la categoría: React JS

React JS

Instalar React

$ yarn add react react-dom --dev
$ yarn add babel-preset-react --dev
$ yarn add eslint-plugin-react --dev

Agrega este contenido dentro de .eslintrc.js
module.exports = {
    extends: ['eslint:recommended', 'plugin:react/recommended'],

React Components

export defualt class AComponent extends React.Component {

    construct(props) {
        this.state = {
            row = null   

    //Este método es obligatorio
    render() {

Functional Components

const MyButton = ({ disabled, text }) => (
MyButton.defaultProps = {
    text: 'My Button',
    disabled: false
export default MyButton;

Props y state

Props son vlores que recibe el componente que son inmutables, el componente no las va a cambiar
cuando se realiza un evento.
State si las puede cambiar el componente

//Cuando se va a cambiar el state pero se va a utilizar un valor del mismo state se tiene que pasar con una callback
//donde state es el estado actual
this.setState(state => ({
    fourth: state.doneMessage


getDerivedStateFromProps() : This method allows you to update the state of
the component based on property values of the component. This method is called
when the component is initially rendered and when it receives new property
render() : Returns the content to be rendered by the component. This is called
when the component is first mounted to the DOM, when it receives new
property values, and when setState() is called.
componentDidMount() : This is called after the component is mounted to the
DOM. This is where you can perform component initialization work, such as
fetching data.
shouldComponentUpdate() : You can use this method to compare new state or
props with current state or props. Then, you can return false if there's no need to
re-render the component. This method is used to to make your components more
getSnapshotBeforeUpdate() : This method lets you perform operations
directly on DOM elements of your component before they're actually committed
to the DOM. The difference between this method and render() is that
getSnapshotBeforeUpdate() isn't asynchronous. With render() , there's a
good chance that the DOM structure could change between when it's called and
when the changes are actually made in the DOM.
componentDidUpdate() : This is called when the component is updated. It's rare
that you'll have to use this method.

A component that should be rendered as a dialog probably
doesn't need to be mounted at the parent. Using a portal, you can control specifically where
your component's content is rendered

Paquetes utiles

$ npm install --save redux-saga
$ npm install --save redux
$ npm i -S react-redux
$ npm i -D redux-devtools