react-jsx

when multiple React DOM components are used without outer div then JSX won't compile

烈酒焚心 提交于 2020-01-03 15:57:29
问题 Consider this example which won't compile: /** @jsx React.DOM */ var Hello = React.createClass({ render: function() { return <div>Hello</div>; } }); var World = React.createClass({ render: function() { return <div>World</div>; } }); var Main = React.createClass({ render: function() { return ( <Hello /> <World /> ); } }); React.renderComponent(<Main />, document.body); But any of these combinations does work: <div> <Hello /> <World /> </div> <Hello /> //<World /> //<Hello /> <World /> Wanted

Where to apply my moment() function in a react component?

六月ゝ 毕业季﹏ 提交于 2020-01-03 13:56:08
问题 I am trying to do a clock component, simply to give the date and time in local format in a webpage. I imported MomentJS using the command line npm i moment --save in my webpack environment. Next I wrote this in my Clock.jsx component (mostly based on the React example on the website). import React from 'react'; import Moment from 'moment'; export default class Clock extends React.Component { constructor(props) { super(props); this.state = { dateTimestamp : Date.now() }; } tick = () => { this

Detect when mobx observable has changed

北战南征 提交于 2020-01-03 12:33:52
问题 Is it possible to detect when an observable changes in any way? For instance, say you have this: @observable myObject = [{id: 1, name: 'apples'}, {id: 2, name: 'banana' }] And later on, with some user input, the values change. How can I detect this easily? I want to add a global "save" button, but only make it clickable if that observable has changed since the initial load. My current solution is to add another observable myObjectChanged that returns true/false, and wherever a component

In Visual Studio 2012, I get warnings and squiggly lines when trying to write JSX with React JS

梦想与她 提交于 2020-01-03 11:02:21
问题 I am using a separate javascript file to put my React JS JSX in. When I use the example given by the documents, I get tons of Visual Studio warnings and ugly squiggly lines.. I cannot figure out a way around this.. Pretty much a deal breaker for React JS. 回答1: Visual Studio 2012 was released before ReactJs, so you can't really blame them for not supporting it. There is some visual studio stuff here: http://reactjs.net/ You can see support for tooling being asked here: https://github.com

How do I use an SVG in React without using dangerouslySetInnerHTML?

邮差的信 提交于 2020-01-03 05:26:11
问题 I've created a React component for the Facebook icon to be able to use in the footer. Unfortunately it doesn't work unless I use dangerouslySetInnerHTML , so the icon shows up - however it appears broken. Here is the code for the Facebook component: import React from 'react'; import ReactDOM from 'react-dom'; class Facebook extends React.Component{ render() { var svgString = '<?xml version="1.0" encoding="iso-8859-1"?><!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version:

How to loop through object in JSX using React.js

六月ゝ 毕业季﹏ 提交于 2020-01-02 01:53:57
问题 So I have a React.js component, and I want to loop through an object I import to add HTML options to it. Here is what I tried, which is both ugly and does not work: import React from 'react'; import AccountTypes from '../data/AccountType'; const AccountTypeSelect = (props) => { return ( <select id={props.id} className = {props.classString} style={props.styleObject}> <option value="nothingSelected" defaultValue>--Select--</option> { $.each(AccountTypes, function(index) { <option val={this.id}

Typescript: how to set type of children in React Component?

隐身守侯 提交于 2020-01-02 01:09:29
问题 Can i set type of children in TypeScript? For example i have such Components class UserProfile extends React.Component<{ id: number }, void>{ } class Thumbnail extends React.Component<{ children: UserProfile[] }, void>{ } class UsersList extends React.Component<void, void>{ public render() { return ( <div> <Thumbnail><UserProfile id={1} /></Thumbnail> <Thumbnail><UserProfile id={2} /></Thumbnail> </div> ) } } I want to define what particular children are supported in Thumbnail component in

Mysterious ESLint Parsing Error

萝らか妹 提交于 2020-01-02 00:54:19
问题 On line 4 of the following code, ESLint is giving me a parsing error saying: Unexpected token = I'm wondering why this is the case? The code runs properly. What am I doing wrong? import { Component, PropTypes } from 'react'; export default class MainApp extends Component { static propTypes = { children: PropTypes.any.isRequired } componentWillMount() { require('./styles/main.styl'); } render() { return ( <div> {this.props.children} </div> ); } } 回答1: You cannot have properties inside classes,

React JSX integration with erb and Ruby block syntax

我与影子孤独终老i 提交于 2020-01-01 18:02:13
问题 In my app/assets/javascripts/components/navbar.js.jsx.erb I can write something like this in the render function of my component (I'm using the gem react-rails): class Navbar extends React.Component { render() { return( <div className="navbar-header"> <ul> <li> <%= link_to root_path, className: 'navbar-brand' do %> <span className='glyphicon glyphicon-home'></span>   <%= I18n.t('menu.now') %> <% end %> </li> <li><%= link_to I18n.t('menu.archive'), archive_path%></li> </ul> </div> ); } } All

What ES6 features are supported in JSX?

谁说胖子不能爱 提交于 2020-01-01 04:29:10
问题 I'm using React with JSX with react-tools to compile the JSX code to JavaScript. What ES6 features are supported in JSX with the harmony option enabled? 回答1: Thanks to kangax for the compatibility table Update : Just use babel (previously named 6to5) to compile your JSX. It's faster and has better es6 support anyway. 来源: https://stackoverflow.com/questions/27414384/what-es6-features-are-supported-in-jsx