react-jsx

ReactJS: “this.props” is not a function when child component calls parent

走远了吗. 提交于 2019-12-03 02:05:23
I have written this code and am currently wrangling with a bug in an onClick event. I have two events, the onClick event on the child element and the onChange event on the top-level parent element. The expected behaviour should be to change the activeAccount variable currently held in the Container component. To do this, I added an onClick handler on the AccountRow component that should then call the top-level parent's onChange function. However, the line 'this.props.onChange(this.props.account)', in handleClick: function(e) { this.props.onChange(this.props.account); }, meant to call the

What is the purpose of having functions like componentWillMount in React.js?

半腔热情 提交于 2019-12-02 23:54:22
I have been writing components in React.js recently. I have never had to use methods like componentWillMount and componentDidMount . render is indispensable. getInitialState and other helper methods I wrote also come in handy. But not the two aforementioned lifecycle methods. My current guess is that they are used for debugging? I can console.log out inside them: componentWillMount: function() { console.log('component currently mounting'); }, componentDidMount: function() { console.log('component has mounted'); } Are there any other uses? componentDidMount is useful if you want to use some non

How to make react.js play nice together with zurb reveal modal form

女生的网名这么多〃 提交于 2019-12-02 22:23:47
I am trying to integrate zurb reveal with form into react component. So far next code properly displays modal form: ModalForm = React.createClass({ handleSubmit: function(attrs) { this.props.onSubmit(attrs); return false; }, render: function(){ return( <div> <a href="#" data-reveal-id="formModal" className="button">Add new</a> <div id="formModal" className="reveal-modal" data-reveal> <h4>Add something new</h4> <Form onSubmit={this.handleSubmit} /> <a className="close-reveal-modal">×</a> </div> </div> ); } }); The Form component is pretty standard: Form = React.createClass({ handleSubmit:

React.js without JSX - “Warning: Something is calling a React component directly. Use a factory or JSX instead”

冷暖自知 提交于 2019-12-02 20:49:49
I'm trying to use React.js component without JSX and receive such warning: Warning: Something is calling a React component directly. Use a factory or JSX instead. See: http://fb.me/react-legacyfactory I've visited link but suggested createFactory solution didn't help me :/ app.js var React = require('react/addons'); var TagsInput = React.createFactory(require('./tagsinput')); // no luck var TagsComponent = React.createClass({ displayName: "TagsComponent", saveTags: function () { console.log('tags: ', this.refs.tags.getTags().join(', ')); }, render: function () { return ( React.createElement(

Using for loops and switch cases in React to dynamically render different components

我是研究僧i 提交于 2019-12-02 17:59:19
I am trying to render components conditionally using switch case in React JSX. I am trying to build something that reads from a specific json structure and renders the data. Since there can be many different components and data, I am trying to render it dynamically. See my code below, I am not getting any errors but the components aren't getting rendered. Inside my html , I can only see . This means the loop isn't working. I tried using the same loop in vanilla JS and it works. var myPackage = [{ sectionInfo:[{ elementType: 1, text: "This is text from element type 1" }] }, { sectionInfo:[{

Rendering comma separated list of links

拜拜、爱过 提交于 2019-12-02 17:28:25
I'm trying to output a list of comma separated links and this is my solution. var Item = React.createComponent({ render: function() { var tags = [], tag; for (var i = 0, l = item.tags.length; i < l; i++) { if (i === item.tags.length - 1) { tag = <span><Tag key={i} tag={item.tags[i]} /></span>; } else { tag = <span><Tag key={i} tag={item.tags[i]} /><span>, </span></span>; } tags.push(tag); } return ( <tr> <td> {item.name} </td> <td> {tags} </td> </tr> ); } }); I was just wondering if there was a better, more clean way to accomplish this? Thanks At Khan Academy we use a helper called intersperse

React: Keyboard Event Handlers All 'Null'

微笑、不失礼 提交于 2019-12-02 17:15:14
I'm unable to get any of the React SyntheticKeyboardEvent handlers to register anything except null for the event properties. I've isolated the component in a fiddle and am getting the same result as in my application. Can anyone see what I'm doing wrong? http://jsfiddle.net/kb3gN/1405/ var Hello = React.createClass({ render: function() { return ( <div> <p contentEditable="true" onKeyDown={this.handleKeyDown} onKeyUp={this.handleKeyUp} onKeyPress={this.handleKeyPress}>Foobar</p> <textarea onKeyDown={this.handleKeyDown} onKeyUp={this.handleKeyUp} onKeyPress={this.handleKeyPress}> </textarea>

How to pass navigator reference to React Native <Drawer/>?

和自甴很熟 提交于 2019-12-02 14:51:13
问题 Using react-native-drawer ( https://github.com/root-two/react-native-drawer ) in my index.ios.js, I have the following set up and trying to pass 'navigator' reference into content's < DrawerPanel /> of < Drawer />. I console.log(this.props.navigator) in < DrawerPanel /> but a wrong navigator reference is passed in, when I am attempting to do similar to this.props.navigator.replace() inside < DrawerPanel /> How can I pass in the right navigator constructor like that of being passed into

React router only works with root path

纵然是瞬间 提交于 2019-12-02 11:17:05
Only root route works. /about, /home shows "Cannot GET /home" in browser. If i replace each route path with "/" then the corresponding component is rendering. But there seems to be problem when i try to render certain route eg /home. You have to configure your server to work with Router.HistoryLocation -- that is, it needs to always serve your index.html page regardless of the route. app.get('*', function (req, res) { res.render('index'); }); Check out the docs here: React Router Docs - HistoryLocation 来源: https://stackoverflow.com/questions/32276514/react-router-only-works-with-root-path

reactjs es6, .map function not triggering onclick

心不动则不痛 提交于 2019-12-02 10:05:35
Reactjs, ES6 issue: Very simple onclick event in a .map function not working. When I inspect it, this in handleclick function represent _this5 and this in .map bind represents _this6. class LineItem extends React.Component{ constructor(props){ super(props); } handleClick=(event)=> { console.log(this); } render(){ return( <div> { this.props.Lines.map((line,i)=> { return <div className="subcontent"> <div className="row-wrapper plan-content"> <Row className="show-grid" onClick={this.handleClick()}> <span>{line.lineName}</span> </Row> </div> <LineStatus LineInfo={line} Camp={this.props.Camp} key=