reactjs-flux

this.state.foo is different in _onChange and different in render()?

廉价感情. 提交于 2019-12-08 11:08:37
问题 In _onChange method, I wait for a change in this.state.name . On the change _updateArticle method is called: _onChange() { var team = this.getTeamState(); this.setState({name: team}); console.log(this.state.name); //"Boston Celtics" //this should have changed but it didn't this.unbind("articles"); this._updateArticle(); }, then in _updateArticle a new reference is created using this new state. _updateArticle(team) { var teamRef = new Firebase(this.props.baseUrl + team + "/results"); console

Why I can't access component state in render in reactjs

纵然是瞬间 提交于 2019-12-08 04:23:29
问题 Trying to learn react.js I was trying to set the state of the component in getInitialState and access it in render using this.state.myproperty but seems I am doing something silly wrong .Here is what I have done so far. app.jsx this is my entry point var React = require('react'); var App = require('./components/App'); React.render( <App />, document.getElementById('content') ); /components/App.jsx var React = require('react'); var UserStore = require('../stores/UserStore'); var ActionCreator

jQuery UI Sortable with React.js buggy

久未见 提交于 2019-12-07 06:40:10
问题 I have a sortable list in React which is powered by jQuery UI. When I drag and drop an item in the list, I want to update the array so that the new order of the list is stored there. Then re-render the page with the updated array. i.e. this.setState({data: _todoList}); Currently, when you drag and drop an item, jQuery UI DnD works, but the position of the item in the UI does not change, even though the page re-renders with the updated array. i.e. in the UI, the item reverts to where it used

Why should addChangeListener be in componentDidMount instead of componentWillMount?

若如初见. 提交于 2019-12-06 23:02:42
问题 I saw this line as an answer to another question on here: "componentWillMount should be componentDidMount, or else you'll leak event emitters in node." and I don't really understand it. Can someone explain with more detail? More info: Building a react application with flux, as part of the initial render, a child component computes some data. Ideally, after this data is computed, I would like to call an action that updates the store's state with a portion of this new data. Normally, updating

Should the action or store be responsible for transforming data when using React + Flux?

独自空忆成欢 提交于 2019-12-06 08:11:11
问题 When using React and Flux, it's standard practice to make API calls from actions, and then store the resulting data in a Store class. But who should be responsible for transforming that data after it's been stored? Example: I've got an EntryStore that keeps hold of objects representing shopping list items. I have a number of filters that I can apply to them (e.g "show only dairy "). I currently have this working by calling EntryActions.filterEntries('dairy') , which the dispatcher then passes

How to wait to render view in react.js until $.get() is complete?

给你一囗甜甜゛ 提交于 2019-12-06 07:30:24
问题 Hello I'm writing a chat client in reactjs and want to render my components with data retrieved from a REST call. However, my component is rendered before the REST request returns with data; this causes errors as I am calling this.props within my children components. var MainChat = React.createClass({ getInitialData: function(){ var c = [] $.get("http://127.0.0.1:8888/test/sampledata.php?user=123", function(data, status) { console.log("Data: "+ data+ "\nStatus: " + status); c = data }) },

React Flux: what's the point of actions?

↘锁芯ラ 提交于 2019-12-06 06:41:47
In Flux , what is the point of using actions , instead of just letting the component publish directly to the dispatcher ? What is it that I can't do without actions ? The action creators decouple the component from the dispatcher. You could replace the dispatcher and related pieces with something else and the components would not need to change. 来源: https://stackoverflow.com/questions/29677779/react-flux-whats-the-point-of-actions

Dispatcher not registering callbacks in jest unit tests

依然范特西╮ 提交于 2019-12-06 05:59:20
问题 I'm writing unit tests for a store in a react+flux app. I followed the example of setting up the mock dispatcher here, and my unit test looks like this: jest.dontMock "../../app/scripts/stores/item_store.coffee" jest.dontMock "object-assign" describe 'ItemStore', -> ShopConstants = require "../../app/scripts/constants/shop_constants.coffee" ShopDispatcher = undefined ItemStore = undefined callback = undefined actionBuildQueryString = source: "VIEW_ACTION" action: type: ShopConstants

Flux + React.js - Callback in actions is good or bad?

百般思念 提交于 2019-12-06 03:23:43
问题 Let me explain the problem that I've faced recently. I have React.js + Flux powered application: There is a list view of articles (NOTE: there are multiple of of different lists in the app) and article details view inside it. But there is only one API endpoint per each list which returns array of articles. In order to display the details I need to find article by id in array. That works pretty fine. I trigger action which makes request to server and propagates store with data, when I go to

Who is responsible to fetch data from server in a flux app with caching?

扶醉桌前 提交于 2019-12-05 23:40:52
问题 In the flux webchat example application and in the README diagram, it seems like the action creator should retrieve the data from the server. The problem I see is that no fetch might be required if the data is already in the store. The store is the only one to know, so the action need to actually be dispatched. I think it's better to fetch dernormalized data when possible, to minimize xhr calls. If the store is denormalized e.g. MessageStore will contain all the data it needs to render