react-jsx

Redirect using react-router in redux middleware

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 08:48:23
I've created a middleware that checks if a request returns an invalid access response. If the status is a 401, I want to redirect the user to the login page Here's the middleware code import React from 'react'; import { push, replace } from 'react-router-redux'; const auth_check = ({ getState }) => { return (next) => (action) => { if(action.payload != undefined && action.payload.status==401){ push('login'); console.log('session expired'); } // Call the next dispatch method in the middleware chain. let returnValue = next(action); return returnValue } } export default auth_check; Including it in

React.js without JSX - “Warning: Something is calling a React component directly. Use a factory or JSX instead”

六眼飞鱼酱① 提交于 2019-12-03 07:21:13
问题 I'm trying to use React.js component without JSX and receive such warning: Warning: Something is calling a React component directly. Use a factory or JSX instead. See: http://fb.me/react-legacyfactory I've visited link but suggested createFactory solution didn't help me :/ app.js var React = require('react/addons'); var TagsInput = React.createFactory(require('./tagsinput')); // no luck var TagsComponent = React.createClass({ displayName: "TagsComponent", saveTags: function () { console.log(

How to implement Stripe with React Native?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 06:58:54
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 name for the Stripe SDK? Lastly, by using fetch to Stripe API endpoints in place of stripe.js , would

Render a React component based on its name

梦想的初衷 提交于 2019-12-03 06:17:24
Context: I am developing a widget-based webapp, (like the defunct iGoogle, where users can choose which widgets they want to display). Each widget is a React component. Simplified example: Here are 2 different widgets var HelloWidget = React.createClass({ render: function() { return <div>Hello {this.props.name}</div>; } }); var HiWidget = React.createClass({ render: function() { return <div>Hi {this.props.name}</div>; } }); As a user, I have chosen the HiWidget and my name is "dude" so when the system gets my preferences from the persistence layer it looks like this: var dataFromDb = { type:

Rendering comma separated list of links

心已入冬 提交于 2019-12-03 04:57:58
问题 I'm trying to output a list of comma separated links and this is my solution. var Item = React.createComponent({ render: function() { var tags = [], tag; for (var i = 0, l = item.tags.length; i < l; i++) { if (i === item.tags.length - 1) { tag = <span><Tag key={i} tag={item.tags[i]} /></span>; } else { tag = <span><Tag key={i} tag={item.tags[i]} /><span>, </span></span>; } tags.push(tag); } return ( <tr> <td> {item.name} </td> <td> {tags} </td> </tr> ); } }); I was just wondering if there was

Using for loops and switch cases in React to dynamically render different components

天大地大妈咪最大 提交于 2019-12-03 04:46:25
问题 I am trying to render components conditionally using switch case in React JSX. I am trying to build something that reads from a specific json structure and renders the data. Since there can be many different components and data, I am trying to render it dynamically. See my code below, I am not getting any errors but the components aren't getting rendered. Inside my html , I can only see . This means the loop isn't working. I tried using the same loop in vanilla JS and it works. var myPackage

How to repeat an element n times using JSX

浪子不回头ぞ 提交于 2019-12-03 04:04:26
问题 I am using React/JSX in my app in order to accomplish what I want, also, Lodash. I need to repeat an element a certain amount of times depending on a condition, how should I do that? Here is the element: <span className="busterCards">♦</span>; And I am assigning it like this: let card; if (data.hand === '8 or more cards') { card = <span className="busterCards">♦</span>; } So in this case, I need to repeat the element 8 times. What should be the process using Lodash? 回答1: Here you go: let card

Using React.findDOMNode in TypeScript

╄→尐↘猪︶ㄣ 提交于 2019-12-03 03:16:49
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" value="Post" /> </form>; } } Calling console.log(React.findDOMNode(this.refs['author'])); gives me

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

☆樱花仙子☆ 提交于 2019-12-03 02:13:38
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? Sure, use a ternary: render() { return ( this.state.name ? <NavItem>{this.state.name}</NavItem> : null ); } or even shorter render() { return ( this.state.name && <NavItem>{this.state.name}</NavItem> ); } Sure

React: Keyboard Event Handlers All 'Null'

六眼飞鱼酱① 提交于 2019-12-03 02:09:39
问题 I'm unable to get any of the React SyntheticKeyboardEvent handlers to register anything except null for the event properties. I've isolated the component in a fiddle and am getting the same result as in my application. Can anyone see what I'm doing wrong? http://jsfiddle.net/kb3gN/1405/ var Hello = React.createClass({ render: function() { return ( <div> <p contentEditable="true" onKeyDown={this.handleKeyDown} onKeyUp={this.handleKeyUp} onKeyPress={this.handleKeyPress}>Foobar</p> <textarea