react-jsx

Browserify fails to create bundle with babelify transform (TypeError: Path must be a string.)

杀马特。学长 韩版系。学妹 提交于 2019-12-04 03:25:39
I've written a gulp task to compile my .jsx and .js scripts into a bundle using watchify and babelify as a transform. For some reason my gulp script seems to be choking on the transform and I'm not sure why: gulp.task('browserify', function() { var bundle = watchify(browserify('./app/jsx/client/index.jsx', { extensions: ['.js', '.jsx'], debug: process.env.NODE_ENV === 'development' })); bundle.transform(babelify); bundle.on('update', function() { rebundle(bundle); }); function rebundle(bundle) { return bundle.bundle() .on('error', function(error) { console.log(error.stack, error.message); this

Why doesn't ReactJS autogenerate keys for dynamic children?

。_饼干妹妹 提交于 2019-12-04 02:21:31
When coding ReactJS I have to supply keys for dynamic children. For example: render() { const {options} = this.state const availableOptions = options.map(opt => { return ( <option key={opt.id} value={opt.id}>{opt.displayValue}</option>} ) } return ( <select onChange={this._onOptionSelect}> {availableOptions} </select> ) } I understand why they keys are there. But why do I have to give them? Couldn't react just assign a running number or UUIDv4 or something else? Related doc: http://facebook.github.io/react/docs/multiple-components.html#dynamic-children Tl;dr You need to assign a unique key to

JSX Spread Attributes on client side non-ES6 browsers

穿精又带淫゛_ 提交于 2019-12-04 02:00:12
问题 ReactJS JSX has a method for easily adding lots of properties to a component: var props = {}; props.foo = x; props.bar = y; var component = <Component {...props} />; These are called Spread Attributes. https://facebook.github.io/react/docs/jsx-spread.html#spread-attributes The ... notation is called a Spread operator that it used in ES6. This is easy to use if you are rendering out everything on the server side using Babel, etc, but if you are wanting to create and render Components in the

indeterminate checkbox in React JSX

雨燕双飞 提交于 2019-12-04 00:47:16
How do I render an indeterminate checkbox in JSX? Here's what I've tried: render() { return <input type="checkbox" checked={this.props.state === "checked"} indeterminate={this.props.state === "indeterminate"} /> } However, indeterminate is not an attribute on the HTMLElement , but a property . How do I set properties from React / JSX? You can use the componentDidMount step (which is invoked after the initial rendering) to set that property: componentDidMount() { React.findDOMNode(this).indeterminate = this.props.state === "indeterminate"; } If you want that property to be updated with

Dispatch a Redux action with the subsequent action as payload to show a snackbar or dialog of Material UI

我怕爱的太早我们不能终老 提交于 2019-12-04 00:28:24
I'm using React with Redux and Material UI to build a webapp. The webapp is made of several pages and components. I know that a snackbar or dialog should be directly connected to what the user is doing. However, I'd like to make the snackbar and dialog independent on the pages and components. A use case therefore is displaying a message like background synchronization of your data failed and an action retry now . My idea was to render the snackbar on a page called RootFrame , which is used to wrap all other pages and to dispatch the text of the snackbar as payload of an action. My Redux action

React render component using its name

こ雲淡風輕ζ 提交于 2019-12-04 00:02:49
I am experimenting React.js and it is working really well. I am wondering if it is possible to inject classes to other classes like so: var Container = React.createClass({ render: function() { <{this.props.implComponent}/> } }); Assuming implComponent has been passed like so: React.render( <Container implComponent="somePredefinedVariable" />, document.getElementById('content') ); This does not work because of a Syntax error. I can easily understand why. In other words I'd like to inject classes to other classes based on names. Is this possible? How can I do that? Brigand You were close. You

ReactJS change background image dynamically?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 23:16:12
I was trying to change background image style dynamically for the following div: Here is my component for changing it, render: function() { var divImage = { backgroundImage : "url(" + this.state.song.imgSrc + "),url(" + this.state.nextImgSrc + ");" }; return ( <li> <div ref="image-pane" className="player" style={divImage}></div> </li> ) } Thanks for the help daniula You haven't specified when would you like to change backgroundImage , so I've created version which changes it with onClick : React.createClass({ getInitialState: function () { nextImg: false, }, handleClick: function () { this

Replace part of string with tag in JSX

浪子不回头ぞ 提交于 2019-12-03 22:31:31
I'm trying to replace parts of a string with JSX tags, like so: render: function() { result = this.props.text.replace(":",<div className="spacer"></div>); return ( <div> {result} <div> ); } But given that this.props.text is Lorem : ipsum , it results in <div> Lorem [object Object] ipsum. </div> Is there a way to solve this or another way to replace parts of a string with JSX tags? When you pass a JSX element to replace() as the second argument, that element is converted to a string because replace() expects a string as a second argument. What you need to do is convert your string to an array

How to get value of textbox in React?

☆樱花仙子☆ 提交于 2019-12-03 20:40:59
问题 I just started using React.js, and I'm just not sure whether there is a special way to get the value of a textbox, returned in a component like this: var LoginUsername = React.createClass({ render: function () { return ( <input type="text" autofocus="autofocus" onChange={this.handleChange} /> ) }, handleChange: function (evt) { this.setState({ value: evt.target.value.substr(0, 100) }); } }); 回答1: As described in documentation You need to use controlled input . To make an input - controlled

How to implement Stripe with React Native?

心不动则不痛 提交于 2019-12-03 16:58:10
问题 I have researched on how to implement Stripe using React native, but have not found a solid way to so. Apparently, React Native does not support http module so would have to use Stripe API using fetch (as explained in http://blog.bigbinary.com/2015/11/03/using-stripe-api-in-react-native-with-fetch.html). So my question is, is using fetch method to Stripe API endpoints a good alternative to stripe.js ? And would I be missing out on anything by not using stripe.js ? Also, is stripe.js another