redux

react-redux 之Provider和connect

和自甴很熟 提交于 2020-02-03 22:57:56
react-redux:redux是数据存储和管理的工具,但是想要在react中使用redux,并不能直接将store、action和react组件建立连接,所以就需要react-redux来结合react和redux Provider:提供的是一个顶层容器的作用,实现store的上下文传递:在原应用组件上包裹一层,使原来整个应用成为Provider的子组件,接收Redux的store作为props,通过context对象传递给子孙组件上的connect connect:使用connect可以把state和dispatch绑定到react组件,使得组件可以访问到redux的数据。函数最终返回的是将state和dispatch绑定到Connect之后的新组件。React-Redux 将所有组件分成两大类:UI 组件(presentational component)和容器组件(container component) UI 组件又称为"纯组件",即它纯函数一样,纯粹由参数决定它的值:特征 只负责 UI 的呈现,不带有任何业务逻辑 没有状态(即不使用 this.state 这个变量) 所有数据都由参数( this.props )提供 不使用任何 Redux 的 API 容器组件: 负责管理数据和业务逻辑,不负责 UI 的呈现 带有内部状态 使用 Redux 的 API React

react-redux的使用

喜你入骨 提交于 2020-02-03 22:51:14
在react-redux 框架中,给我提供了两个常用的API来配合Redux框架的使用,其实在我们的实际项目开发中,我们完全可以不用react-redux框架,但是如果使用此框架,就如虎添翼了。 我们来简单聊聊这两个常用的API connect() Provider 组件 React-Redux 将所有组件分成两大类:UI 组件(presentational component)和容器组件(container component)。 UI 组件 UI 组件有以下几个特征。 只负责 UI 的呈现,不带有任何业务逻辑 没有状态(即不使用this.state这个变量) 所有数据都由参数(this.props)提供 不使用任何 Redux 的 API 2、因为不含有状态,UI 组件又称为"纯组件",即它跟纯函数一样,纯粹由参数决定它的值。 下面就是一个 UI 组件的例子。 const Title = value => <h1>{value}</h1>; 因为不含有状态,UI 组件又称为"纯组件",即它纯函数一样,纯粹由参数决定它的值。 你可能会问,如果一个组件既有 UI 又有业务逻辑,那怎么办?回答是,将它拆分成下面的结构:外面是一个容器组件,里面包了一个UI 组件。前者负责与外部的通信,将数据传给后者,由后者渲染出视图。 React-Redux 规定,所有的 UI 组件都由用户提供

TypeError: Object(…) is not a function in react-redux

巧了我就是萌 提交于 2020-02-03 07:57:24
问题 While I was trying to createStore in react-redux I get this strange error. I don't know why as I did this before in different app there it was working fine. TypeError: Object(...) is not a function ./src/index.js C:/projects/facebook/facebook-react/src/index.js:14 11 | import rootReducer from './rootReducer'; 12 | import registerServiceWorker from './registerServiceWorker'; 13 | > 14 | const store = createStore( 15 | rootReducer, 16 | composeWithDevtools(applyMiddleware(thunk)) 17 | ); View

TypeError: Object(…) is not a function in react-redux

∥☆過路亽.° 提交于 2020-02-03 07:54:37
问题 While I was trying to createStore in react-redux I get this strange error. I don't know why as I did this before in different app there it was working fine. TypeError: Object(...) is not a function ./src/index.js C:/projects/facebook/facebook-react/src/index.js:14 11 | import rootReducer from './rootReducer'; 12 | import registerServiceWorker from './registerServiceWorker'; 13 | > 14 | const store = createStore( 15 | rootReducer, 16 | composeWithDevtools(applyMiddleware(thunk)) 17 | ); View

How to add <Link> react-router per each Material-UI TableRow?

点点圈 提交于 2020-02-03 06:01:47
问题 How to add link per TableRow in .map? *my error is validateDOMNesting(...): cannot appear as a child of "< a >" im using react router react-router-dom how to add link in every loop of .map in Table TableRow? import React, { Fragment } from 'react' import { Paper } from 'material-ui' import Table from 'material-ui/Table'; import TableBody from 'material-ui/Table/TableBody'; import TableCell from 'material-ui/Table/TableCell'; import TableHead from 'material-ui/Table/TableHead'; import TableRow

How to add <Link> react-router per each Material-UI TableRow?

我的梦境 提交于 2020-02-03 06:00:29
问题 How to add link per TableRow in .map? *my error is validateDOMNesting(...): cannot appear as a child of "< a >" im using react router react-router-dom how to add link in every loop of .map in Table TableRow? import React, { Fragment } from 'react' import { Paper } from 'material-ui' import Table from 'material-ui/Table'; import TableBody from 'material-ui/Table/TableBody'; import TableCell from 'material-ui/Table/TableCell'; import TableHead from 'material-ui/Table/TableHead'; import TableRow

How to add <Link> react-router per each Material-UI TableRow?

你离开我真会死。 提交于 2020-02-03 05:59:45
问题 How to add link per TableRow in .map? *my error is validateDOMNesting(...): cannot appear as a child of "< a >" im using react router react-router-dom how to add link in every loop of .map in Table TableRow? import React, { Fragment } from 'react' import { Paper } from 'material-ui' import Table from 'material-ui/Table'; import TableBody from 'material-ui/Table/TableBody'; import TableCell from 'material-ui/Table/TableCell'; import TableHead from 'material-ui/Table/TableHead'; import TableRow

Where to do calculations in redux?

余生长醉 提交于 2020-02-02 06:08:25
问题 General question, but will include a specific example: where is the correct place to loop through state/stored data to extract calculations? So here, I need to make some calculations to display in a 'stats' sidebar that requires looping through each of an array of clients (could be a rather large number of clients) to pull out different props/values and add them all together. I did it in render just to get it to work which I know is incorrect, but does it happen still in the component and

Where to do calculations in redux?

烂漫一生 提交于 2020-02-02 06:08:12
问题 General question, but will include a specific example: where is the correct place to loop through state/stored data to extract calculations? So here, I need to make some calculations to display in a 'stats' sidebar that requires looping through each of an array of clients (could be a rather large number of clients) to pull out different props/values and add them all together. I did it in render just to get it to work which I know is incorrect, but does it happen still in the component and

Fish Redux系列学习之认识view、action

删除回忆录丶 提交于 2020-02-01 23:17:49
继续上一篇文章: Fish Redux系列学习之新建page以及认识state 如上图,现在我们学习的是 buildview 这个组件,说白了, buildView 是我们写页面的地方,跟写普通flutter的page页面一样,我们将页面都写在这里面。 View部分: view部分的代码: import 'package:fish_redux/fish_redux.dart' ; import 'package:flutter/material.dart' ; import 'package:miaoxun/utils/image_constant.dart' ; import 'package:miaoxun/utils/images_util.dart' ; import 'state.dart' ; import 'action.dart' ; Widget buildView ( SplashState state , Dispatch dispatch , ViewService viewService ) { return Scaffold ( backgroundColor : Color . fromRGBO ( 255 , 209 , 0 , 1 ) , body : Center ( child : Image . asset ( ImageUtil .