GithubHelp home page GithubHelp logo

conorhastings / redux-proptypes-connect Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 5 KB

mapping global state to components utilizing properties defined in React PropTypes

HTML 6.53% JavaScript 93.47%

redux-proptypes-connect's Introduction

React-Redux PropTypes connect

I've been reading a lot about the idea of local component state backed by a global state. The general idea being you define state on the local component but it is backed up by another state source that is global, this could be client side, server side or a combination of both. The idea is that you gain all the pluses that come with global state (not having to update in many places, less side effects, etc...) while also gaining the pluses of local state (easy to see exactly what this component needs...).

React PropTypes serve a semi-similar purpose, it's a component level definition of the data that this component expects to receive through props. Utilizing the connect function provided by react-redux and PropTypes (though it doesn't for all intents and purposes need to be PropTypes) from react we can achieve something close to local component state backed by global state. The slice of state that each component received is directly defined by the PropTypes of that component. See the src folder for a very basic implementation.

redux-proptypes-connect's People

Contributors

conorhastings avatar

Watchers

 avatar

redux-proptypes-connect's Issues

should this return the connected component?

then it could look more like this

import React from 'react';
import mapPropsFromPropTypes from './map-props-from-proptypes';

const Colors = ({colors}) => {
  return (
    <ul>
      {colors.map((color) => {
        return <li key={color}>{color}</li>
      })}
    </ul>
  );
}

Colors.propTypes = {
  colors: React.PropTypes.array.isRequired
};

export default mapPropsFromPropTypes(Colors);

looks cleaner, and the connect part is hidden from the end user.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.