react-jsx

Expected corresponding JSX closing tag for input Reactjs

China☆狼群 提交于 2019-11-29 22:50:06
While creating a component in Reactjs with input fields error occurs Error: Parse Error: Line 47: Expected corresponding JSX closing tag for input at http://localhost/chat-react/src/script.js:47:20 </div> var Main = React.createClass({ render: function() { return ( <div className="card-action"> <i class="mdi-action-account-circle prefix"></i> <input id="icon_prefix" type="text" class="validate"> </div> ); } }); You need to close the input element with a /> at the end. <input id="icon_prefix" type="text" class="validate" /> This error also happens if you have got the order of your components

Best practice when adding whitespace in JSX

£可爱£侵袭症+ 提交于 2019-11-29 22:49:37
I understand how (and why ) to add a whitespace in JSX, but I am wondering what's best practice or if any makes any real difference? Wrap both elements in a span <div className="top-element-formatting"> <span>Hello </span> <span className="second-word-formatting">World!</span> </div> Add them on one line <div className="top-element-formatting"> Hello <span className="second-word-formatting">World!</span> </div> Add space with JS <div className="top-element-formatting"> Hello {" "} <span className="second-word-formatting">World!</span> </div> Because &nbsp causes you to have non-breaking spaces

Listen to keypress for document in reactjs

扶醉桌前 提交于 2019-11-29 22:46:17
I want to bind to close the active react bootstrap popover on escape press .Here is the code _handleEscKey:function(event){ console.log(event); if(event.keyCode == 27){ this.state.activePopover.hide(); } }, componentWillMount:function(){ BannerDataStore.addChangeListener(this._onchange); document.addEventListener("click", this._handleDocumentClick, false); document.addEventListener("keyPress", this._handleEscKey, false); }, componentWillUnmount: function() { BannerDataStore.removeChangeListener(this._onchange); document.removeEventListener("click", this._handleDocumentClick, false); document

What does JSX stand for?

假如想象 提交于 2019-11-29 22:10:55
What does JSX stand for? I am referring to the JSX that is defined as a XML-like syntax extension to ECMAScript, which has become quite popular with the increasing popularity of ReactJS. JSX stands for J ava S cript X ML. With React, it's an extension for XML-like code for elements and components. Per the React docs and as you mentioned: JSX is a XML-like syntax extension to ECMAScript without any defined semantics From the quote above, you can see that JSX doesn't have defined semantics, it's just an extension to JavaScript that allows to write XML-like code for simplicity and elegance, and

Reactjs: page refreshing upon `onClick` handle of Button?

牧云@^-^@ 提交于 2019-11-29 19:16:34
问题 I have the following block inside my render() (which is a Bootstrap Button: https://react-bootstrap.github.io/components.html#buttons-options): <Button type="simpleQuery" onClick={this.handleEntailmentRequest.bind(this)}> Query </Button> and the following function: handleEntailmentRequest() { console.log("handle request "); } Whenever I click on the button I can see that the the "handle request" question appears in the console log, but suddenly disappears. My understanding is that something

Child to parent communication in React (JSX) without flux

被刻印的时光 ゝ 提交于 2019-11-29 18:41:35
问题 I'm really new to React, and I'm pulling my hair out trying to solve what seems to me to be a simple problem. Here's a picture of the component I've built. Color Picking Component What I'm trying to accomplish seems trivial, but literally every article I've read explaining what to do has told me something different, and not one of the solutions has worked. It breaks down to this: When a user clicks on a tag, it builds out a tray and loops through an array of colors to build color buttons.

How do I use react.js without a bundler?

此生再无相见时 提交于 2019-11-29 17:44:07
问题 Recently I have been playing around with react.js and I like the speed that I can develop working UI components. I have now created quite a few components and I would like to distribute some of them among different .jsx files. Every thing I've read says that I should be using a bundler like browserify or webpacker whenever moving to production. However I am against this idea. Part of the reason I like developing in javascript is because its a scripted language and there is no compiler to muck

Conditional Rendering in React js

浪尽此生 提交于 2019-11-29 17:14:35
I have added a condition in rendering and suddenly it stops displaying. Here is the code am using. {this.state.sdata.map((sdata, i) => {i < 5 && <ServiceNavItem key={i} onClick={()=>this.handleSelect(i)}{...sdata} /> } ) } I want to display only 4 items from sdata. Anybody please help. You forgot to return the element from map body, as well as you need to return null for all the entries of array after i >= 5 . Write it like this: {this.state.sdata.map((sdata, i) => { if(i < 5) return <ServiceNavItem key={i} onClick={()=>this.handleSelect(i)}{...sdata} /> return null; }) } But i will suggest

babel watch SyntaxError: Unexpected token

佐手、 提交于 2019-11-29 15:27:10
When I uses babel to watch a jsx file. But there is a syntax error. Before that, I uses react-tools to watch, and everything is fine. SyntaxError: assets/js/chat/chat.jsx: Unexpected token (258:16) 256 | if (this.props.isOpen) { 257 | return ( > 258 | <div className="modal-overlay"> | ^ 259 | <ReactCSSTransitionGroup transitionName={this.props.transitionName}> 260 | <div className="chat-modal"> 261 | {this.props.children} The following is my code. var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup; var Modal = React.createClass({ render: function() { if (this.props.isOpen) { return

React is expected to be globally available

蓝咒 提交于 2019-11-29 13:36:26
I'm playing with React (@13.3) with babel and webpack. I have a component that's defined like this: import BaseComponent from './BaseComponent'; export default class SomeComponent extends BaseComponent { render() { return ( <div> <img src="http://placekitten.com/g/900/600"/> </div> ); } } But I get the following error: Uncaught ReferenceError: React is not defined I understand the error: the JSX bit is compiled into React.createElement(...) but React isn't in the current scope since it's not imported. My questions is: What's the clean way to work around this issue? Do I have to somehow expose