react-jsx

React: setting the disabled attribute based on a state

丶灬走出姿态 提交于 2019-12-22 02:04:24
问题 I'd like to set the disabled attribute on a Button based on component's state, something like this: render() { return ( <button type="button" {this.state.submitting ? 'disabled' : ''} onClick={ this.handleSubmit }>Submit</button> ); } At the moment I get an Unexpected token error on the opening {, what am I missing? 回答1: You can set disabled property through boolean value, like this <button type="button" disabled={this.state.submitting} onClick={this.handleSubmit} > Submit </button> Example

React Router: Cannot read property 'pathname' of undefined

有些话、适合烂在心里 提交于 2019-12-22 01:26:05
问题 I've just started learning React and got stuck at this error. Uncaught TypeError: Cannot read property 'pathname' of undefined at new Router Here is my code: var React = require('react'); var ReactDOM = require('react-dom'); var { Route, Router, IndexRoute } = require('react-router'); var hashHistory = require('react-router-redux') var Main = require('./components/Main'); ReactDOM.render( <Router history={hashHistory}> <Route path="/" component={Main}> </Route> </Router>, document

Does the className attribute take on the role of the id attribute in Reactjs?

让人想犯罪 __ 提交于 2019-12-21 16:58:21
问题 Since id attributes are rarely used in Reactjs components due to the fact that id attributes imply that the component will not be reused, then are className attributes used instead of id's? If this is the case, then what is the Reactjs equivalent of the class attribute in HTML? 回答1: className is used for class names for CSS styling, just as elsewhere. You can give something a unique className for styling purposes the same way you might give otherwise give it an id , sure, but that doesn't

How to use whiteSpace: 'pre-wrap' on React

不羁岁月 提交于 2019-12-21 07:40:07
问题 How can I use the style whiteSpace: 'pre-wrap' on React I have a div that need to render the text using the format with spaces render() { <div style={{whiteSpace: 'pre-wrap'}} keep formatting keep spaces </div> } 回答1: JSX collapses whitespaces, in this case you can use dangerouslySetInnerHTML like so var Component = React.createClass({ content() { const text = ` keep formatting keep spaces `; return { __html: text }; }, render: function() { return <div style={{ whiteSpace: 'pre-wrap' }}

WebStorm/PhpStorm warning for react attributes in jsx like className

回眸只為那壹抹淺笑 提交于 2019-12-21 07:25:21
问题 I can not remove following warning in react code. "Attribute className is not allowed here". Warning in PhpStorm Unknown HTML tag attribute can not be set to camelcase only lower case is saved, and turning the check off is not helping. Settings in Languages & Frameworks > JavaScript > Libraries Can you help me I have warnings for every attribute in jsx. Editor is set jsx harmony. 回答1: My problem with warnings in jsx was solved by instaling React-Template plugin. 回答2: I'm a little late on the

react js - use svg linear gradient not working

南笙酒味 提交于 2019-12-21 05:21:55
问题 i have a circle and a grradient to fill in it, i put in the gradient and call him in path by style fill. import React,{PropTyoes} from 'react'; import {connect} from 'react-redux'; import * as Actions from '../controllers/Actions'; export default class MyComp extends React.Component { constructor(props, context){ super(props, context); } render(){ return ( <svg xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" viewBox="0 0 983.4 983.4"> <g> <linearGradient id=

Render a React component based on its name

我与影子孤独终老i 提交于 2019-12-20 20:01:06
问题 Context: I am developing a widget-based webapp, (like the defunct iGoogle, where users can choose which widgets they want to display). Each widget is a React component. Simplified example: Here are 2 different widgets var HelloWidget = React.createClass({ render: function() { return <div>Hello {this.props.name}</div>; } }); var HiWidget = React.createClass({ render: function() { return <div>Hi {this.props.name}</div>; } }); As a user, I have chosen the HiWidget and my name is "dude" so when

How babel and JSX related or differ?

泄露秘密 提交于 2019-12-20 15:33:57
问题 I am learning on React JS and I have got information on JSX and babel. But I am not getting clarity on how these are helping React and how these or differ from each other 回答1: React JS while building an app using React, you can create the components/views in two ways using standard React object and methods using JSX JSX JSX is a separate technology from React and completely optional while building React application, however it makes life much easier when you combine JSX with React. Let's see

Declaring Const With Curly Braces in JSX

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 11:40:10
问题 I'm just getting started with React Native and getting used to JSX syntax. Is that what I'm talking about? Or am I talking about TypeScript? Or... ES6? Anyway... I've seen this: const { foo } = this.props; Inside a class function. What is the purpose of the curly braces and what's the difference between using them and not using them? 回答1: It is destructuring assignment. The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or

reactjs es6, .map function not triggering onclick

自作多情 提交于 2019-12-20 07:29:19
问题 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(