reflux / refluxjs

A simple library for uni-directional dataflow application architecture with React extensions inspired by Flux
BSD 3-Clause "New" or "Revised" License
5.36k stars 330 forks source link

How to JUST receive one actions's data in components #518

Closed KrisLeeCoder closed 7 years ago

KrisLeeCoder commented 7 years ago

Component : loginFom. Store: UserStore, both login and register actions are listened in it. Actions: login, with children completed and failed; register, with children completed and failed. The login and register action will send a ajax request, and call completed if request succeed with user's data, or call failed with the error message. In loginForm component, I just need the login.success action's returned data.

So, HOW can I use store in react components without dealing with the whole triggered data? Or, HOW can I just receive one method's triggered data from store in components?

BryanGrezeszak commented 7 years ago

Components don't care about receiving actions. They dispatch them. It goes:

component -> action -> store -> back to component again

So the relevant question is the "So, HOW can I use store in react components without dealing with the whole triggered data?"

There are multiple ways of dealing with that.

There's storeKeys for normal declarative style usage to filter out all but just the store properties you want.

And for more imperative/manual usage, you use mapStoreToState to filter as well as format what parts of a store's state go into your component.