The state shape would be something like:
{
products: [
{
price: 7500,
name: "Some product",
//other details
},
{
import React, {Component} from 'react'; | |
import {connect} from 'react-redux'; | |
import FunctionPlot from './function-plot'; | |
require("../../css/functions.css"); | |
function mapStateToProps(state) { | |
return { | |
expression: state.expression |
<?php | |
namespace AppBundle\Services; | |
use AppBundle\Entity\AnEntityRepo; | |
use AppBundle\Services\OtherService; | |
use AppBundle\Services\ThirdService; | |
class Features | |
{ |
var Hello = React.createClass({ | |
render: function() { | |
return <div>{this.props.name}</div>; | |
} | |
}); | |
var HelloInput = React.createClass({ | |
render: function() { | |
return ( | |
<div><input value={this.props.name} onChange={ev=>this.props.update(ev.target.value)}/></div> |
//Action type constants don't have to have the same name as their value. | |
//Really, the const string value doesn't even have to be related to the action itself. | |
const UPDATE = 'randomValueGeneratedSomehow'; | |
let updateThing = function(newValue) { | |
return { | |
type: UPDATE, | |
payload: newValue, | |
} | |
} |
//Some store thing that has onUpdate as a method for setting listeners. | |
store.onUpdate(function(newState) { | |
ReactDOM.render( | |
<App state={newState} />, | |
document.getElementById("root") | |
); | |
}); | |
//You either need to call render once here to get things started, or cause a state update. | |
ReactDOM.render( |
The state shape would be something like:
{
products: [
{
price: 7500,
name: "Some product",
//other details
},
{
var React = require('react'); | |
//This would be passed props like: | |
{ | |
btns: [ | |
{id: 'btn1', label: 'Button 1'}, | |
{id: 'btn2', label: 'Button 2'}, | |
{id: 'btn3', label: 'Button 3'}, | |
], | |
onBtnClick: function(btnId) { |
Is it unreasonable to have data that only exist in your selectors and as props passed down from them? For example, I might have a short list of possible items. An action creator sends the new item. The reducer replaces the state with the new item. The component could have the list of items itself, but then it's not associated with state as much as the component. If the list comes from the selector, it's more associated with the state, and can be used in multiple components.
>samssh, yeah you make a
const React = require('react'); | |
const ReactDOM = require('react-dom'); | |
class Component extends React.Component { | |
constructor(props) { | |
super(props); | |
this.handleButton = this.handleButton.bind(this); | |
} | |
handleButton(ev) { | |
//name needs to be cast to an int since attributes are all strings. |
Before trying to learn React or Redux, or use Webpack/Browserify or Babel, you should make sure you know Javascript at least reasonably well. A great resource learning Javascript is EloquentJS. If you have never programmed before, another great place to learn JS is Codecademy. The best resource for referencing the basic web languages (HTML, CSS, Javascript, and the DOM API) is the Mozilla Developer Network, commonly referred to as MDN.