redux

Map properties to state in react-redux

北城以北 提交于 2019-12-21 09:23:11
问题 I have a component that uses state to provide data to user. For example <div>this.state.variableInState</div> . This component can dispatch some method (for example on onClick action). I'm currently using react-redux an connect method to map store to props . Is there a way I can setState after dispatch? // actions export function executeAction() { return function (dispatch, getState) { dispatch({ type: 'MY_ACTION', payload: axios.get('/some/url') }); }; } // reducer export default function

Can a Redux store lead to a memory leak?

别说谁变了你拦得住时间么 提交于 2019-12-21 09:19:55
问题 I have a dashboard application with several charts getting updated on a set interval. My first thought was to update the data in the store and then let all charts feed from there. But could that lead to a memory leak? Since Redux creates a new store every time the data changes and keeps the old ones. Would a ~2mb data every second pile up and crash the application? The alternative I see is to keep the data in the local state (with setState). I hope some more experienced React/Redux devs can

react-redux redirect to other page after login

本小妞迷上赌 提交于 2019-12-21 09:05:10
问题 action.js : export const login = creds => { console.log(`${url}/login`); const requestOptions = { method: "POST", headers: { Accept: "application/json", "Content-Type": "application/json" }, body: creds }; return function(dispatch) { dispatch({ type: LOGIN_REQUEST }); function timer() { return fetch(`${url}/login`, requestOptions).then(response => { if (!response.ok) { console.log(response); return response.json().then(json => { var error = new Error(json.message); error.response = response;

how to render a react component using ReactDOM Render

為{幸葍}努か 提交于 2019-12-21 08:25:47
问题 _Header (cshtml) <div id="Help"></div> export default class Help { ReactDOM.render( <Help/>, document.getElementById('Help') ); } Help.js (component) } My goal is to render a help button on header. I've Created div tag with id help-modal , and a component rendering help button. I am connection those two in help.js by ReactDOM.render(.........); when I do npm run dist and dotnet run , and see the browser I couldn't see the button on header . Can any one help on this please ?? 回答1: You are

how to render a react component using ReactDOM Render

跟風遠走 提交于 2019-12-21 08:25:13
问题 _Header (cshtml) <div id="Help"></div> export default class Help { ReactDOM.render( <Help/>, document.getElementById('Help') ); } Help.js (component) } My goal is to render a help button on header. I've Created div tag with id help-modal , and a component rendering help button. I am connection those two in help.js by ReactDOM.render(.........); when I do npm run dist and dotnet run , and see the browser I couldn't see the button on header . Can any one help on this please ?? 回答1: You are

Warning: setState(…): Cannot update during an existing state transition with redux/immutable

大城市里の小女人 提交于 2019-12-21 07:56:12
问题 I am getting the error Warning: setState(...): Cannot update during an existing state transition (such as within render or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to componentWillMount . I found the cause to be const mapStateToProps = (state) => { return { notifications: state.get("notifications").get("notifications").toJS() } } If I do not return notifications there it works.

【13】react 之 redux(2)

被刻印的时光 ゝ 提交于 2019-12-21 07:16:34
转载:http://www.cnblogs.com/MuYunyun/p/6530715.html 什么情况需要用redux? 用户的使用方式复杂 不同身份的用户有不同的使用方式(比如普通用户和管理员) 多个用户之间可以协作 与服务器大量交互,或者使用了WebSocket View要从多个来源获取数据 简单说,如果你的UI层非常简单,没有很多互动,Redux 就是不必要的,用了反而增加复杂性。多交互、多数据源场景就比较适合使用Redux。 设计思想: Web 应用是一个状态机,视图与状态是一一对应的。 所有的状态,保存在一个对象里面。 Redux工作流程: 首先,用户发出 Action。 store.dispatch(action); 然后,Store 自动调用 Reducer,并且传入两个参数:当前 State 和收到的 Action。 Reducer 会返回新的 State 。 let nextState = todoApp(previousState, action); State 一旦有变化,Store 就会调用监听函数。 // 设置监听函数 store.subscribe(listener); listener 可以通过 store.getState() 得到当前状态。如果使用的是 React,这时可以触发重新渲染 View。 function listerner() {

dispatch an action on componentDidMount (react/redux)

北城余情 提交于 2019-12-21 06:55:52
问题 I am relativity new to react/redux. There for I want to ask a (perhaps a philosophic) question. Is it ok to to dispatch an action (e.g. to trigger an api-call) on componentDidMount of a react component? If not, why and where should I dispatch the action? If yes, then no further questions? :) 回答1: Yes, dispatching an action on componentDidMount() is OK, and even the recommended thing to do since it will not slow down the initial UI render. Since the function runs after the component has

axios http always returns with empty data

白昼怎懂夜的黑 提交于 2019-12-21 06:08:29
问题 I asked this question before and wasn't able to get an answer. I was able to do use method: 'get' like below to get it working so it was okay but this time I need to use post. In a different project (using react, redux, php, webpack, xampp) the same issue has resurfaced and I am trying to figure it out. So here it is: register.php echo $_GET['task']; index.js const values = {task: 'doSomething', username: 'username'} axios({ url: "./server/register.php", timeout: 20000, method: 'get', params:

axios http always returns with empty data

醉酒当歌 提交于 2019-12-21 06:07:14
问题 I asked this question before and wasn't able to get an answer. I was able to do use method: 'get' like below to get it working so it was okay but this time I need to use post. In a different project (using react, redux, php, webpack, xampp) the same issue has resurfaced and I am trying to figure it out. So here it is: register.php echo $_GET['task']; index.js const values = {task: 'doSomething', username: 'username'} axios({ url: "./server/register.php", timeout: 20000, method: 'get', params: