react-jsx

PHPStorm JSX/React syntax highlighting

喜欢而已 提交于 2019-12-06 16:40:19
问题 I'm using PHPStorm 8.0.3 for my current project, but unfortunately it doesn't support JSX. In my React components (which are then compiled by Browserify) HTML gets underlined in red and invalidated: This is just a small component, but it surely gets pretty annoying with bigger ones. Also code formatting doesn't work as expected. Is there a (hard to find) setting which enables the correct syntax highlighting? If there is no such setting, is it possible to download a corresponding package? If

Typescript custom @types package for @types/react-router

試著忘記壹切 提交于 2019-12-06 14:22:01
问题 My project use react with typescript. I need to use react-breadcrumbs to show Breadcrumb for react-router. Now I add two @type package to My package.json "dependencies": { "@types/react-breadcrumbs": "^1.3.7", "@types/react-router": "^3.0.8" } react-breadcrumb need to use route.props.name to show name for breadcrumb, but when I use @type package in npm the Route.d.ts file has not name Props in the interface RouteProps. interface RouteProps extends IndexRouteProps { path?: RoutePattern; }

How to redirect to a page in React Native?

你说的曾经没有我的故事 提交于 2019-12-06 09:28:59
问题 this.props.navigator.push({ component: MainView, passProps: {selectedTab: 'home', message: 'this is the messages'}, }); Is this the only way to redirect page? That said, when condition hit, I want to render another page, what is the right way to do in React Native? 回答1: There are quite a few different ways to do redirect the page. From the React Native docs, here are the methods available to Navigator: push(route) - Navigate forward to a new route pop() - Go back one page popN(n) - Go back N

React JSX and Django reverse URL

大兔子大兔子 提交于 2019-12-06 07:49:40
I'm trying to build some menu using React and need some Django reverse urls in this menu. Is it possible to get django url tag inside JSX? How can this be used? render: function() { return <div> <ul className={"myClassName"}> <li><a href="{% url 'my_revese_url' %}">Menu item</a></li> </ul> </div>; } You could create a script tag in your page to inject the values from Django into an array. <script> var menuItems = [ {title: 'Menu Item', url: '{% url "my_reverse_url" %}'}, {title: 'Another Item', url: '{% url "another_reverse_url" %}'}, ]; </script> You could then pass the array into the menu

Google Map Api Marker not showing with Reactjs

烈酒焚心 提交于 2019-12-06 05:46:48
I am trying to display a google map with a marker. I am using React.js. The map displays in the correct location, but the marker does not show and I get multiple 'object is not extensible' error in the browser console The code looks like this /** @jsx React.DOM */ var Map = React.createClass({ initialize: function() { var lat = parseFloat(this.props.lat); var lng = parseFloat(this.props.lon); var myPosition = new google.maps.LatLng(lat,lng); var mapOptions = { center: myPosition, zoom: 8 }; var map = new google.maps.Map(this.getDOMNode(), mapOptions); var marker = new google.maps.Marker(

Reactjs: CJSX Nested Conditionals

狂风中的少年 提交于 2019-12-06 04:57:39
What is the correct syntax to handle nested conditional logic in a React component? React.createClass render: -> <div> {if @props.showList {for item in @props.myItems {item} } else } </div> The for loop (on its own) can be rendred; the if/else conditional (on its own) can be rendered. However, nesting the for loop inside the conditional fails. Any help would be very much appreciated. I haven't tested it, but based on how normal JSX works you only need the {expression} thing to escape from JSX mode. The program starts in JS mode (or CS here), and when an element tag is encountered it enters JSX

Testing a React Modal component

这一生的挚爱 提交于 2019-12-06 03:57:28
问题 I'm sorry, but I've been having the toughest time trying to test closing my React Modal by clicking a button. The Modal is as simple as can be, and I've tried everything I can think of or find, but I still can't query its children. The Modal component: var React = require('react'); var Modal = require('react-bootstrap').Modal; var Button = require('react-bootstrap').Button; var MyModal = React.createClass({ ... render: function() { return ( <Modal className="my-modal-class" show={this.props

How do I utilize dot notation when rendering components?

蹲街弑〆低调 提交于 2019-12-06 03:41:36
问题 I have a simple component which is supposed to render different kind of fields into my form component: import React from "react"; export default class Field extends React.Component { render() { switch (this.props.type) { case 'textarea': { return ( <div className="col-xs-12"> <textarea placeholder={this.props.placeholder} name={this.props.name} > </textarea> </div> ) } case 'text': { return ( <div className="col-md-6 col-lg-4"> <input type="text" placeholder={this.props.placeholder} name=

Flux + React.js - Callback in actions is good or bad?

百般思念 提交于 2019-12-06 03:23:43
问题 Let me explain the problem that I've faced recently. I have React.js + Flux powered application: There is a list view of articles (NOTE: there are multiple of of different lists in the app) and article details view inside it. But there is only one API endpoint per each list which returns array of articles. In order to display the details I need to find article by id in array. That works pretty fine. I trigger action which makes request to server and propagates store with data, when I go to

Code coverage on JSX tests with Istanbul

别来无恙 提交于 2019-12-06 01:52:40
问题 I am trying to instrument my code to get some coverage up and running, but something is slipping through my fingers. I launch istanbul with: node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha -- -u exports -R spec And my mocha.opts looks like this: app/assets/javascripts/components/**/*-mocha.jsx --compilers jsx:mocha/compiler.js Everything seems to run fine (the tests run, at least), but the only coverage that I get is on the files used to compile the JSX to JavaScript (used in