How to use Presentational/Container components in a Redux app – Jakob Lind

I wrote about when and how to use presentational/container components #reactjs #redux

  • Either present something visual (presentational component) OR fetch data (container component).
  • You can use the container/presentational pattern when using both regular Ajax calls inside your components, or when you are using Redux to fetch data.
  • When you start coding your Redux app, you usually start with a wrapper component that receives the data from the Redux store.
  • It is possible to connect Redux to any React component in your application.
  • In a real world application you might need to do more advanced refactorings of the presentational components.

Have you read about Presentational/Container pattern but are still not sure how it looks when it’s used correctly? When should you use it and when should you NOT use it?
Continue reading “How to use Presentational/Container components in a Redux app – Jakob Lind”

Optimizing React Performance with Stateless Components — SitePoint

Optimizing React Performance with Stateless Components  #reactjs #javascript

  • First, the Super Basics
    import React, { Component } from ‘react’

    class User extends Component {
    render() {
    const { name, highlighted, userSelected } = this.props
    console.log(‘Hey User is being rendered for’, [name, highlighted])
    return div
    h3
    style={{fontStyle: highlighted ?

  • For example, something like this:
    import React, { Component } from ‘react’

    class Users extends Component {
    constructor(props) {
    super(props)
    this.state = {
    otherData: null,
    users: [{name: ‘John Doe’, highlighted: false}]
    }
    }

    async componentDidMount() {
    try {
    let response = await let data = await response.json()
    this.setState({otherData: data})
    } catch(err) {
    throw err
    }
    }

    toggleUserHighlight(user) {
    this.setState(prevState = {
    users: prevState.users.map(u = {
    if (u.name === user.name) {
    u.highlighted = !

  • import React, { PureComponent } from ‘react’

    class User extends PureComponent {

    render() {
    const { name, highlighted, userSelected } = this.props
    console.log(‘Hey User is being rendered for’, [name, highlighted])
    return div
    h3
    style={{fontStyle: highlighted ?

  • Our first attempt at re-writing it back to a functional component but with recompose.pure looks like this:
    import React from ‘react’
    import { pure } from ‘recompose’

    const User = pure(({ name, highlighted, userSelected }) = {
    console.log(‘Hey User is being rendered for’, [name, highlighted])
    return div
    h3
    style={{fontStyle: highlighted ?

  • ‘italic’ : ‘normal’}}
    onClick={event = {
    userSelected()
    }}{name}/h3
    /div
    })

    export default User

    As you might notice, if you run this, the User component still re-renders even though the props (the name and highlighted keys) don’t change.

Writing inefficient React components can cause them to rerender too often. Peter Bengtsson looks at ways of creating and optimizing stateless components.
Continue reading “Optimizing React Performance with Stateless Components — SitePoint”

Usage with React

A #reactjs key difference between presentational and container Components #javascript

  • Most of the components we’ll write will be presentational, but we’ll need to generate a few container components to connect them to the Redux store.
  • In addition to reading the state, container components can dispatch actions.
  • Todo is a single todo item.
  • Rather than write container components, we will generate them using the connect() function provided by React Redux, as you will see below.
  • A container component is just a React component that uses store.subscribe() to read a part of the Redux state tree and supply props to a presentational component it renders.

Read the full article, click here.


@ferroariel: “A #reactjs key difference between presentational and container Components #javascript”


From the very beginning, we need to stress that Redux has no relation to React. You can write Redux apps with React, Angular, Ember, jQuery, or vanilla JavaScript.


Usage with React