react-jsx

Use <code> or similar tags in ReactJS using JSX

本秂侑毒 提交于 2020-01-11 05:14:45
问题 I am trying to use ReactJS with JSX to create a proof of concept for a styleguide. I wanted to be able to display the raw html of how to call on components doing this. JSX is ignoring my <code> tags and rendering out the component This is what i have tried so far Display HTML code in HTML <blockquote> <pre> <code> <VideoPlayer ref="videoplayer" preload={this.props.preload} classes={this.props.classes} videoID={this.props.videoID} controls="controls" /> </code> </pre> </blockquote> I was

React render components from string

依然范特西╮ 提交于 2020-01-11 03:52:30
问题 Is it possible to dynamically render a React component from a string? Basically I have pages' content coming from the database and I want to have React componentes within the content. An example of what I'm trying to achieve: var html_string = '<i>React Component Rendered</i>: <Hello name="World" />'; var Hello = React.createClass({ render: function() { return <strong>Hello {this.props.name}</strong>; } }); function createMarkup() { return {__html: html_string}; }; var App = React.createClass

Unexpected token when rendering React component

时光怂恿深爱的人放手 提交于 2020-01-10 04:45:25
问题 This is a snippet of my component code: renderEditor() { return ( <FroalaEditor base='https://cdnjs.cloudflare.com/ajax/libs/froala-editor/2.3.4' value={this.state.value} /> ); } render() { return ( {this.renderEditor()} ); } But when I run this code I get an unexpected token error at {this.renderEditor()} . Why does this happen and how can I fix it? 回答1: You have to wrap your method invocation in a JSX element or else Babel won't recognize the return statement as JSX, or an inline JSX

When to use anonymous functions in JSX

主宰稳场 提交于 2020-01-06 21:13:26
问题 can someone explain the difference between an anonymous function <button onClick={() => this.functionNameHere()}></button> and calling the function like below <button onClick={this.functionNameHere()}></button> and also when to use either (such as different scenarios to use one over the other). 回答1: In ES6 , with the first scenario "this" refers to the Component where the function called belongs to. <button onClick={() => this.functionNameHere()}></button> is equivalent to <button onClick=

Avoid using dangerouslySetInnerHTML when wrapping HTML in React.js

江枫思渺然 提交于 2020-01-06 19:53:17
问题 I have this functionality for highlighting certain characters in the HTML of my component: highlightQuery() { // will output the text response from the Model, but also highlight relevant words if they match the search query // that the user input let input = this.props.model.get('value'); if(!this.state.hasMatch){ return input; } let query = this.props.matched.query, index = this.props.model.get('searchIndexes')[this.props.matched.index]; const replaceBetween = (str, start, end, what) => {

update state or parent component in react

可紊 提交于 2020-01-05 08:00:15
问题 I've recently found a nice solution for a very similar problem but I don't know why it doesn't work in my next example. What I am trying to do is: I have created a Component which consists of two input fields, onSubmit of the Form the state, which is an array, of the parent Component should be pushed with the value of the two input fields. Note The name of the parent Component is "Test". The Name of the component with the input fields ,that should update the parents state is named "CreateDogs

How can I pass refs into variable of NavigationBar routeMapper (React Native)?

坚强是说给别人听的谎言 提交于 2020-01-05 05:37:10
问题 Following is the UPDATED code -- I am trying to implement react-native-drawer from https://github.com/root-two/react-native-drawer and the variable I passed into NavigationBarRouteMapper logs openDrawer() function properly, yet when the left nav button is clicked it does nothing: class practice extends Component { ... openDrawer(){ this._drawer.open() } render() { return ( <Drawer content={<DrawerPanel/>} openDrawerOffset={100} ref={(ref) => this._drawer = ref} type='static' tweenHandler=

React JS: onWheel bubbling stopPropagation not working

醉酒当歌 提交于 2020-01-04 06:43:34
问题 TL;DR: See my jsfiddle link where scrolling child div up till bottom/top should not start scrolling parent. I tried using e.stopPropagation() which didn't work. So need solution (without using mixins). My Code: http://jsfiddle.net/vmvrphjn/ //////////HTML CODE <script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script> <div id="container"> <!-- This element's contents will be replaced with your component. --> </div> ////////CSS CODE .childScroll{ max-height:

React: Concatenate string for key

隐身守侯 提交于 2020-01-03 17:06:56
问题 I am creating a list of list and want to put a unique key for each element. When I use the React Dev Tool, the new key is "2016-10,-,football". Why does it have commas in it? What is the correct way to specify a key when I want "2016-10-football"? React Dev Tool Console import React from 'react' import ReactDOM from 'react-dom' const dates = ['2016-10', '2016-11', '2016-12']; const sports = ['football', 'baseball', 'basketball']; const Dates = ( { dates, sports } ) => { return ( <ul> { dates

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

谁说胖子不能爱 提交于 2020-01-03 15:58:01
问题 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