react-jsx

Nested comments in Reactjs

帅比萌擦擦* 提交于 2019-12-03 16:43:42
I have the following json: { "comments":[ { "id":1, "comment_text":"asdasdadasdsadsadadsa", "author":"adsfasdasdsad", "post_id":1, "ancestry":null, "archived":false, "created_at":"2014-10-16T23:16:44.173Z", "updated_at":"2014-10-16T23:16:44.173Z", "is_moderated":false, "avatar_url":null, "slug":null, "blog_id":2, "children":[ ] }, { "id":2, "comment_text":"idlsfghlskdhvbsldfhjdslifds\nzf\ndsf\nds\nf\ns\nf\ns\nfds\nfsdjghfsdligjhsepfiguhefdliguhefldiughfeliughnfesg\nf\nsg\ns\ng\ns\ndf\nsd\nf\nsdgsofughlefidughls;uhgsuhg.vskjfhglsiuhg.sfv", "author":"asdsdasdad", "post_id":1, "ancestry":null,

react js - use svg linear gradient not working

落花浮王杯 提交于 2019-12-03 16:39:12
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="linear-gradient" gradientUnits="userSpaceOnUse" x1="1041.6901" y1="169.485" x2="1383.9301" y2="169.485"

If the props for a child component are unchanged, does React still re-render it?

百般思念 提交于 2019-12-03 13:14:30
Suppose I have the following pairing of parent and child components in React: var ChildComponent = React.createClass({ getDefaultProps: function(){ return { a: 'a', b: 'b', c: 'c' } }, render: function() { return ( /* jshint ignore:start */ <div className={'child' + (this.props.b ? ' modifierClass' : '')} something={this.props.a}> {this.props.c} </div> /* jshint ignore:end */ ); } }); var ParentComponent = React.createClass({ componentDidMount: function(){ //After 10 seconds, change a property that DOES NOT affect the child component, and force an update setTimeout(function(){ this.setState(

React.js: Is it possible to namespace child components while still using JSX to refer to them?

你说的曾经没有我的故事 提交于 2019-12-03 12:56:15
So let's say I have a component called ImageGrid and it is defined as below: window.ImageGrid = React.createClass({ render: function() { return ( <div className="image-grid"> <ImageGridItem /> </div> ); } }); As you can see it includes a child react component called ImageGridItem . Which is defined below. window.ImageGridItem = React.createClass({ render: function() { return ( <div className="item-container">something</div> ); } }); This works fine as long as both are directly properties of window . But this is kind of horrible so I'd like to group up all my react components under a namespace

Using React.findDOMNode in TypeScript

淺唱寂寞╮ 提交于 2019-12-03 12:47:42
问题 I'm following the React Tutorial and got stuck on how to use React.findDOMNode . Here is my code: export class CommentForm extends React.Component<{}, {}> { handleSubmit(e: React.FormEvent) { e.preventDefault(); console.log(React.findDOMNode(this.refs['author'])); } render() { return <form className="commentForm" onSubmit={ e => this.handleSubmit(e) }> <input type="text" placeholder="Your name" ref="author" /> <input type="text" placeholder="Say something..." ref="text" /> <input type="submit

W3C HTML validation for React JSX files

◇◆丶佛笑我妖孽 提交于 2019-12-03 12:12:59
When working on front-end projects I always like to work with linting tools. They prevent from dumb mistakes to serious smelly code pieces. Linting tools also suggest improvements and optimisations. Validating and linting HTML means using the W3C Validator. When working with vanilla JavaScript projects I use the grunt-html Grunt NPM module. And when working with Angular 1.x I use the grunt-html-angular-validate module, which is the same validator but adapted to Angular requirements (non standard attributes or incomplete HTML documents will not fire errors or warnings). However I have tried to

React: Can I check if a state exists before rendering it

两盒软妹~` 提交于 2019-12-03 11:40:27
问题 I'm new to React and I've made a navbar that displays the users name user <NavItem eventKey={4} href="#">{this.state.name}</NavItem> but the problem is if the user is not signed in, I get an error due to this.state.name being undefined. Is there some way I can check if this.state.name is defined before rendering it as part of the navbar or is there a better way to get rid of this error? 回答1: Sure, use a ternary: render() { return ( this.state.name ? <NavItem>{this.state.name}</NavItem> : null

What ES6 features are supported in JSX?

倖福魔咒の 提交于 2019-12-03 11:28:36
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? 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

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

╄→гoц情女王★ 提交于 2019-12-03 09:28:54
问题 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

Dynamically Loading Local Images with ReactJS

為{幸葍}努か 提交于 2019-12-03 09:02:12
I'm trying to render several images from an array, passed onto an "Image" component as a property. However, for whatever reason, the local images I would like to render are not showing up. If I load an image hosted at a web address, that image will show up, indicating that there is nothing wrong with the "imageSource" property being passed onto the Image component. I have tried playing with the source format like so: let source = 'require(./img/' + props.imageSource + ")"; or trying: <img src={{uri: source}} role="presentation" style={style.image} /> ...but nothing I do makes any difference.