Automatic redirect after login with react-router

React Router v3 This is what I do var Router = require(‘react-router’); Router.browserHistory.push(‘/somepath’); React Router v4 Now we can use the <Redirect>component in React Router v4. Rendering a <Redirect> will navigate to a new location. The new location will override the current location in the history stack, like server-side redirects. import React, { Component } … Read more

At what nesting level should components read entities from Stores in Flux?

Most people start out by listening to the relevant stores in a controller-view component near the top of the hierarchy. Later, when it seems like a lot of irrelevant props are getting passed down through the hierarchy to some deeply nested component, some people will decided it’s a good idea to let a deeper component … Read more

What are differences between redux, react-redux, redux-thunk?

Can someone clearly explain how control flow happens in redux ? Redux has (always) a single store. Whenever you want to replace the state in the store, you dispatch an action. The action is caught by one or more reducers. The reducer/s create a new state that combines the old state, and the dispatched action. … Read more

Webpack-dev-server serves a directory list instead of the app page

If you’re using webpack’s dev server you can pass in options to use /public as a base directory. devServer: { publicPath: “https://stackoverflow.com/”, contentBase: “./public”, hot: true }, See the webpack configuration docs, and specifically the webpack dev server docs for more options and general information.

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

Should flux stores, or actions (or both) touch external services?

I’ve seen the flux pattern implemented both ways, and after having done both myself (initially going with the former approach), I believe that stores should be dumb recipients of data from the actions, and that asynchronous processing of writes should live in the action creators. (Async reads can be handled differently.) In my experience, this … Read more

In Flux architecture, how do you manage Store lifecycle?

In a Flux app there should only be one Dispatcher. All data flows through this central hub. Having a singleton Dispatcher allows it to manage all Stores. This becomes important when you need Store #1 update itself, and then have Store #2 update itself based on both the Action and on the state of Store … Read more

tech