Skip to content

Instantly share code, notes, and snippets.

@schmidsi
Last active August 2, 2023 16:45
Show Gist options
  • Save schmidsi/6da59c9a45d0cc2a97f53ed3d8138010 to your computer and use it in GitHub Desktop.
Save schmidsi/6da59c9a45d0cc2a97f53ed3d8138010 to your computer and use it in GitHub Desktop.
How we react/redux
  • React is the V in MVP (Model-View-Controller)
  • It's architecture is similar to the Web Components standard
  • Simple said: You can create your "own html tags" like
  • React then reassembles your components into the DOM and manages the expensive DOM updates (throught diffing a shadow DOM)

Further reading

Class Based Component vs Functional Component

TD:LR; Avoid class based components, but know how they differ.

import React from 'react';

export class MyComponent extends React.Component {
  // must
  render() {
    return (
      <div></div>
    );
  }
  // optional
  constructor(props) {
    super(props);
    this.state = {date: new Date()};
  }
  componentDidMount() {
  }
  componentWillUnmount() {
  }
  // ... https://facebook.github.io/react/docs/react-component.html
}

vs:

import React from 'react';

const functionalComponent = props => (<div>{props.title}</div>)

Key differences:

  • Functional components do not handle internal state and lifecycle

Adding lifecycle methods to functional Components: https://github.com/acdlite/recompose

Handling state: With Redux

Styling

Tooling

  • Predictable application state management
  • Replacement for Meteor Sessions

Redux Flow

In words

  • An events happens, that triggers an action: UI interaction or data update
  • An action has the following shape:
{
  type,     // String, f.e. 'melonchallenge/ADD_PRICE_ENTRY'
  ...params // Other parameters in any form
}
  • This action can be constructed with an actionCreator
  • The action is dispatched on the store
  • The store consists of a state and reducers
  • Reducers take the current state and the dispatched action to calculate a new state
  • State-changes trigger change events

Link to React

Other technologies coming

  • GraphQL (Schema, Validation, PropTypes Generation, Data Query)
  • Flow Type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment