Tag: react redux

TypeError:从Redux使用连接时_this.store.getState不是函数

当我第一次运行服务器node app.js一切都很好,我listening on 5050然后我去localhost:5050 /,我得到这些警告在服务器运行的控制台。 Warning: Failed propType: Required prop `store.subscribe` was not specified in `Provider`. Warning: Failed Context Types: Required child context `store.subscribe` was not specified in `Provider`. 该组件呈现罚款那里,但一旦我去本地主机:5050 / ballerviews我得到这个在服务器上 TypeError: _this.store.getState is not a function at new Connect (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react-redux/lib/components/connect.js:133:38) at [object Object].ReactCompositeComponentMixin.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactCompositeComponent.js:148:18) at [object Object].wrapper [as mountComponent] (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactPerf.js:66:21) at Object.ReactReconciler.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactReconciler.js:37:35) […]

如何在没有npm(Node.js)的情况下设置React和Redux项目?

我已经看到很多video和post用npm(Node.js)configuration项目。 我已经有.Net服务器,我想使用React.JS和Redux。 我可以通过添加下面的JS文件来设置它为React。 <script src="~/Scripts/src/react.min.js"></script> <script src="~/Scripts/src/react-dom.min.js"></script> <script src="~/Scripts/src/browser.min.js"></script> 但是,如何在我的应用程序中包含Redux以使用React和Redux?

在同构反应应用程序中,是否有最简洁的方式在客户端和服务器端获取当前的URL?

我正在开发一个基于这个 React Redux样板的应用程序。 在一个组件中,为了生成社交媒体的可共享URL,我需要获取当前组件的当前URL。 使用React Router,可以从dynamic生成的URL访问组件。 在客户端,我不会有任何问题通过JavaScript document对象,但问题在于服务器端。 我想在Redux存储中提供保存在此config.js文件中的Node.js环境数据,其中保存了主机名 // Node.js environment file config.js require('babel-polyfill'); const environment = { development: { isProduction: false }, production: { isProduction: true } }[process.env.NODE_ENV || 'development']; module.exports = Object.assign({ host: process.env.HOST || 'localhost', port: process.env.PORT, apiHost: process.env.APIHOST || 'localhost', apiPort: process.env.APIPORT }, environment); 并将React Router的location对象设置为组件中的道具,获取path名并完全构造URL。 我所做的就是创build一个初始状态的简单reducer,以保持Node.jsconfiguration环境数据,并且只需要将默认操作包含在与其他应用程序reducer的combineReducers函数中。 const initialState = […]

使用socketio与反应redux

我build立一个小型的聊天应用程序使用反应,redux,socketio和节点与mongoose。 正常情况下,redux通过动作(使API调用和接收数据)stream动并分派数据。 但在我的情况下,套接字将发射到某个事件,但它不会返回数据,直到我们手动发射来自后端的数据。 所以要实现合适的reduxstream程,我应该添加一个套接字事件来检索数据(来自后端),然后调度它或有任何其他适当的方式来实现这一点? 这里是我打算在Actions文件中做的一个示例代码 function sendMessage(data) { return { type: SEND_MESSAGE, payload: data }; } export const sendNewMessage = (socket,data) => { return dispatch => { socket.emit("send message",data); socket.on("new message",function(data){ dispatch(sendMessage(data)); }); }; };

Redux-Thunk“操作必须是普通对象。 使用自定义中间件进行asynchronous操作。“

使用Thunk中间件创build我的商店 import { createStore, applyMiddleware, compose } from 'redux'; import thunk from 'redux-thunk'; const store = createStore( reducer, initialState, applyMiddleware(thunk) ); 并创造我的行动,呼吁一个承诺 export function getArticle(url) { return function (dispatch) { fetchArticle(url).then( article => dispatch(setArticle(article)), ); }; } function fetchArticle(url) { return new Promise((resolve, reject) => { request .get(url) .end( (err, res) => { if (err […]

从完全形成的响应中触发大文件下载

问题 我有一个Node.js端点,当使用以下命令访问时,可以正确触发一个任意大的文件下载: response.setHeader('Content-disposition', 'attachment; filename=' + fileName); response.set('Content-Type', 'text/csv'); response.status(200); result.pipe(response); 其中result是变换stream , response是Express对象 。 当直接访问Chrome,Firefox,Internet Explorer等的terminal时,这种方式可以正常工作。当启用基于令牌的身份validation时,尝试达到终点时会出现问题。 从用户的angular度来看,当他们点击一个button时,文件被下载。 如何使该button在请求标题中find正确的身份validation令牌并导致文件被下载? 一些可能的方法集体讨论 当用户点击button时,它会触发一个由redux-api-middleware处理的动作,这会使GET请求到达终点(authentication令牌自动包含在请求中)。 该中间件将响应保存在由React组件拾取的variables中。 在这个React组件中,如果使用的浏览器(即Chrome和Opera)支持stream, response.body将会存在,所以你可以做如下的事情。 if (response.body) { const csvReader = response.body.getReader(); const textDecoder = new TextDecoder(); const processCsvRow = (csvRow) => { if (csvRow.done) { console.log('Finished downloading file.'); return Promise.resolve(); } // Write to new […]

在第二个动作调用中,React / Redux状态为空

对于React / Redux,我还是比较新的,所以如果这是一个简单的问题,但是我还没有find解决scheme,我很抱歉。 我有两个动作: // DESTINATIONS // ============================================== export const DESTINATION_REQUEST = 'DESTINATION_REQUEST'; export const DESTINATION_SUCCESS = 'DESTINATION_SUCCESS'; export const DESTINATION_FAILURE = 'DESTINATION_FAILURE'; export function loadDestination (params, query) { const state = params.state ? `/${params.state}` : ''; const region = params.region ? `/${params.region}` : ''; const area = params.area ? `/${params.area}` : ''; return (dispatch) […]