How to put methods onto the objects in Redux state?

In Redux, you don’t really have custom models. Your state should be plain objects (or Immutable records). They are not expected to have any custom methods. Instead of putting methods onto the models (e.g. TodoItem.rename) you are expected to write reducers that handle actions. That’s the whole point of Redux. // Manages single todo item … Read more

Should you ever use this.setState() when using redux?

Clear uses of setState would be for UI components that have local display state, but aren’t relevant for the global application. For example a boolean that represents whether a specific dropdown menu is actively displayed doesn’t need to be in global state, so it’s more conveniently controlled by the menu component’s state. Other examples might … Read more

Strategies for server-side rendering of asynchronously initialized React.js components

If you use react-router, you can just define a willTransitionTo methods in components, which gets passed a Transition object that you can call .wait on. It doesn’t matter if renderToString is synchronous because the callback to Router.run will not be called until all .waited promises are resolved, so by the time renderToString is called in … Read more

how to cancel/abort ajax request in axios

Axios does not support canceling requests at the moment. Please see this issue for details. UPDATE: Cancellation support was added in axios v0.15. EDIT: The axios cancel token API is based on the withdrawn cancelable promises proposal. UPDATE 2022: Starting from v0.22.0 Axios supports AbortController to cancel requests in fetch API way: Example: const controller … Read more

How to store Configuration file and read it using React

With webpack you can put env-specific config into the externals field in webpack.config.js externals: { ‘Config’: JSON.stringify(process.env.NODE_ENV === ‘production’ ? { serverUrl: “https://myserver.com” } : { serverUrl: “http://localhost:8090” }) } If you want to store the configs in a separate JSON file, that’s possible too, you can require that file and assign to Config: externals: … Read more

Pretty Printing JSON with React

You’ll need to either insert BR tag appropriately in the resulting string, or use for example a PRE tag so that the formatting of the stringify is retained: var data = { a: 1, b: 2 }; var Hello = React.createClass({ render: function() { return <div><pre>{JSON.stringify(data, null, 2) }</pre></div>; } }); React.render(<Hello />, document.getElementById(‘container’)); Working … Read more

How to dynamically load reducers for code splitting in a Redux application?

Update: see also how Twitter does it. This is not a full answer but should help you get started. Note that I’m not throwing away old reducers—I’m just adding new ones to the combination list. I see no reason to throw away the old reducers—even in the largest app you’re unlikely to have thousands of … Read more

What could be the downsides of using Redux instead of Flux [closed]

Redux author here! I’d like to say you’re going to make the following compromises using it: You’ll need to learn to avoid mutations. Flux is unopinionated about mutating data, but Redux doesn’t like mutations and many packages complementary to Redux assume you never mutate the state. You can enforce this with dev-only packages like redux-immutable-state-invariant, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)