redux

Call state value of another script with redux

房东的猫 提交于 2020-01-22 02:31:11
问题 I want to call a speed value of Screen2.js to Screen1.js . I'm trying with redux, but I'm not very familiar with it. I tried to create a store and return my speed value, and set my speed Screen1 for Screen2 speed. Screen2.js import React, { Component } from 'react'; import { StyleSheet, View, Text } from 'react-native'; import Screen1 from './Screen1'; import { createStore } from 'redux'; import { Provider } from 'react-redux' import { connect } from 'react-redux'; function mapStateToProps

Connect search bar and search results components to global state

偶尔善良 提交于 2020-01-21 19:17:47
问题 I am new to ReactJS and I recently came up with this redux date store that react uses mostly. I am trying to have a good grasp on it. Just for the understanding purpose, I have an Array of Objects stored in the store in a static manner for now. like this: const initialState = { jsonData: [ { "id": "1", "country": "India", "state": "Andhra_Pradesh", "city": "Amaravati", "station": "Secretariat, Amaravati - APPCB", "last_update": "18-12-2019 09:00:00", "pollutant_id": "PM2.5", "pollutant_min":

Connect search bar and search results components to global state

醉酒当歌 提交于 2020-01-21 19:17:29
问题 I am new to ReactJS and I recently came up with this redux date store that react uses mostly. I am trying to have a good grasp on it. Just for the understanding purpose, I have an Array of Objects stored in the store in a static manner for now. like this: const initialState = { jsonData: [ { "id": "1", "country": "India", "state": "Andhra_Pradesh", "city": "Amaravati", "station": "Secretariat, Amaravati - APPCB", "last_update": "18-12-2019 09:00:00", "pollutant_id": "PM2.5", "pollutant_min":

Redux 入门

夙愿已清 提交于 2020-01-21 13:39:34
Redux 是 JavaScript 状态容器,提供可预测化的状态管理。 可以让你构建一致化的应用,运行于不同的环境(客户端、服务器、原生应用),并且易于测试。不仅于此,它还提供 超爽的开发体验,比如有一个 时间旅行调试器可以编辑后实时预览 。 Redux 除了和 React 一起用外,还支持其它界面库。 它体小精悍(只有2kB,包括依赖)。 安装 安装稳定版: npm install --save redux 以上基于使用 npm 来做包管理工具的情况下。 否则你可以直接在 unpkg 上访问这些文件 ,下载下来,或者把让你的包管理工具指向它。 一般情况下人们认为 Redux 就是一些 CommonJS 模块的集合。这些模块就是你在使用 Webpack 、 Browserify 、或者 Node 环境时引入的。如果你想追求时髦并使用 Rollup ,也是支持的。 你也可以不使用模块打包工具。 redux 的 npm 包里 dist 目录 包含了预编译好的生产环境和开发环境下的 UMD 文件。可以直接使用,而且支持大部分流行的 JavaScript 包加载器和环境。比如,你可以直接在页面上的 <script > 标签 中引入 UMD 文件,也可以 让 Bower 来安装 。UMD 文件可以让你使用 window.Redux 全局变量来访问 Redux。 Redux 源文件由

React Redux mapDispatchToProps vs this.props.dispatch

亡梦爱人 提交于 2020-01-21 12:03:29
问题 Until now I used my containers and components actions this way: <Header btnMnuAction={this.props.toggleSidebar} logout={this.props.logout}/> With the mapDispatchToProps function: const mapDispatchToProps = (dispatch) => { return { toggleSidebar: () => { dispatch(toggleSidebar()); }, logout: () => { dispatch(logout()); } } }; Now I tried it this way: <Header btnMnuAction={() => this.props.dispatch(toggleSidebar())} logout={() => this.props.dispatch(logout())} > Please, can someone explain to

React Redux mapDispatchToProps vs this.props.dispatch

徘徊边缘 提交于 2020-01-21 12:02:07
问题 Until now I used my containers and components actions this way: <Header btnMnuAction={this.props.toggleSidebar} logout={this.props.logout}/> With the mapDispatchToProps function: const mapDispatchToProps = (dispatch) => { return { toggleSidebar: () => { dispatch(toggleSidebar()); }, logout: () => { dispatch(logout()); } } }; Now I tried it this way: <Header btnMnuAction={() => this.props.dispatch(toggleSidebar())} logout={() => this.props.dispatch(logout())} > Please, can someone explain to

Actions must be plain object. Use custom middleware

冷暖自知 提交于 2020-01-21 11:44:46
问题 I am using Redux,redux-thunk with react. I am returning an object but still getting the error. authActions.js export function register(){ return (dispatch)=>{ console.log("in register action"); dispatch({type:'auth_user'}) } } calling this action from Register.js using connect and props import * as actions from '../actions/authActions'; class RegisterForm extends React.Component{ handleRegister = (e)=>{ e.preventDefault(); console.log("inside handle register"); console.log(this.props); this

Actions must be plain object. Use custom middleware

白昼怎懂夜的黑 提交于 2020-01-21 11:44:08
问题 I am using Redux,redux-thunk with react. I am returning an object but still getting the error. authActions.js export function register(){ return (dispatch)=>{ console.log("in register action"); dispatch({type:'auth_user'}) } } calling this action from Register.js using connect and props import * as actions from '../actions/authActions'; class RegisterForm extends React.Component{ handleRegister = (e)=>{ e.preventDefault(); console.log("inside handle register"); console.log(this.props); this

Redux入门示例-TodoList

戏子无情 提交于 2020-01-20 22:39:06
Tip 前端技术真是日新月异,搞完 React 不搭配个数据流都不好意思了。 满怀期待的心去翻了翻 flux,简直被官方那意识流的文档折服了,真是又臭又长还是我智商问题?😖 转战 redux ,越看越有意思,跟着文档做了个 TodoList 的入门小例子。 废话不多说,先贴上文章用到例子的源码 https://github.com/TongchengQiu/TodoList-as-redux-demo redux 的 Github 仓库 https://github.com/rackt/redux 还有个中文的 gitbook 翻译文档 http://camsong.github.io/redux-in-chinese/index.html advantage 随着spa(不是SPA,是单页应用)的发展,以 react 来说,组件化和状态机的思想真是解放了烦恼的 dom 操作,一切都为状态。state 来操纵 views 的变化。 然而,因为页面的组件化,导致每个组件都必须维护自身的一套状态,对于小型应用还好。 但是对于比较大的应用来说,过多的状态显得错综复杂,到最后难以维护,很难清晰地组织所有的状态,在多人开发中也是如此,导致经常会出现一些不明所以的变化,越到后面调试上也是越麻烦,很多时候 state 的变化已经不受控制。对于组件间通行、服务端渲染、路由跳转、更新调试

react--需要插件

醉酒当歌 提交于 2020-01-20 12:36:52
npm install -save axios(请求数据) npm install antd --save(Ant Design 是React UI的组件库) npm install --save redux 谷歌浏览器 应用商店搜索redux dev tools安装测试工具: import { createStore } from 'redux'; import reducer from './reducer.js'; const store = createStore( reducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() ); export default store; js解密 npm install --save crypto-js axios.post请求后台数据,发送请求前: axios.interceptors.request.use(function (config) { // 在发送请求之前做些什么 console.log(config); return config; }, function (error) { // 对请求错误做些什么 return Promise.reject(error); }); 来源: CSDN 作者: 人生如初见