react-organism
react-organism copied to clipboard
Add memoization
trafficstars
import makeMemory from 'react-organism/makeMemory'
const remember = makeMemory(3) // Capacity of 3 per action
export const initial = () => ({ posts: null })
// Remember caches given the same props
export const loadPosts = remember(
({ postID }) => fetch(`/posts/${postID}`).then(res => res.json()).then(posts => ({ posts }))
)
export const load = (props, prevProps) => {
//actions.loadPosts() or
return Promise.all([
loadPosts(props) // Will reuse previously cached if props were the same
])
}
Maybe use https://github.com/reactjs/reselect