Skip to content

Instantly share code, notes, and snippets.

@3nvi
Created March 4, 2019 21:45
Show Gist options
  • Save 3nvi/db2e14972b89fb3a38f41a22f8b52441 to your computer and use it in GitHub Desktop.
Save 3nvi/db2e14972b89fb3a38f41a22f8b52441 to your computer and use it in GitHub Desktop.
// selectors.js
export const getItems = state => state.items;
// Component.jsx
import React from 'react';
import { connect } from 'react-redux';
import { getItems } from './selectors';
function MyComponent({ items }) {
return <div>{items.length}</div>
}
const mapStateToProps = state => ({ items: getItems(state) });
export default connect(mapStateToProps)(MyComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment