react-jsx

Require jsx files without specifying extension

戏子无情 提交于 2019-11-30 09:01:49
I am using browserify and watchify , and would like to require() files other than the default extensions .js and .json without specifying the extension, for instance: // Not ideal (tedious) var Carousel = require('./components/Carousel/Carousel.jsx') // Ideal var Carousel = require('./components/Carousel/Carousel') I have tried --extension=EXTENSION as specified in the browserify documentation: "scripts": { "build": "browserify ./src/App.js --transform [ reactify --es6 ] > dist/script.js -v -d --extension=jsx", "watch": "watchify ./src/App.js --transform [ reactify --es6 ] -o dist/script.js -v

Do I need to import React for stateless functional components?

痞子三分冷 提交于 2019-11-30 08:55:21
All around me (e.g. blog posts, code) I see code for React stateless functional components in which React is imported even though it's never used. import React, { PropTypes } from 'react'; function MyComponent({ foo, bar }) { ... return ...; } MyComponent.propTypes = { foo: PropTypes.string.isRequired, bar: PropTypes.func.isRequired } export default MyComponent; I'd argue there is no need for importing React into functional components, and have been assuming it's just a vestige from when the components were classes and is no longer needed. I'm also suprised that my linter doesn't complain

React JSX: Iterating through a hash and returning JSX elements for each key

微笑、不失礼 提交于 2019-11-30 07:48:15
I'm trying to iterate through all the keys in a hash, but no output is returned from the loop. console.log() outputs as expected. Any idea why the JSX isn't returned and outputted correct? var DynamicForm = React.createClass({ getInitialState: function() { var items = {}; items[1] = { name: '', populate_at: '', same_as: '', autocomplete_from: '', title: '' }; items[2] = { name: '', populate_at: '', same_as: '', autocomplete_from: '', title: '' }; return { items }; }, render: function() { return ( <div> // {this.state.items.map(function(object, i){ // ^ This worked previously when items was an

Using 'material-ui' with react-rails gem?

跟風遠走 提交于 2019-11-30 07:35:14
I would like to use the material-ui component library in my Rails 4 app. I am currently using the react-rails gem to add .jsx compilation to the asset pipeline. I have added material-ui via rails-assets in the gemfile like so: source 'https://rails-assets.org' do gem 'rails-assets-material-ui' end And I have required the library in my application.js file like so: //= require material-ui However I keep getting the error "couldn't find file 'material-ui". How can I use the material-ui component library in my Rails app with the react-rails gem? Ok so here is what I have working so far... to the

How to avoid re-rendering the whole List instead of adding the new item to the DOM list in react JS?

我怕爱的太早我们不能终老 提交于 2019-11-30 07:16:19
问题 As in the React demo, and other examples, I see people resetting the State data if one record is added or removed. Which results in the whole list being re-rendered instead of simply appending the latest record, or removing the selected one from the current DOM tree. How is it helpful? Or how can I avoid this case. UPDATE The situation: Facebook feed, you keep scrolling the feed, reach around 5000 feed statuses and many other types of cards. Not just that, each status feed has it's own

How to test decorated React component with shallow rendering

馋奶兔 提交于 2019-11-30 07:07:33
问题 I am following this tutorial: http://reactkungfu.com/2015/07/approaches-to-testing-react-components-an-overview/ Trying to learn how "shallow rendering" works. I have a higher order component: import React from 'react'; function withMUI(ComposedComponent) { return class withMUI { render() { return <ComposedComponent {...this.props}/>; } }; } and a component: @withMUI class PlayerProfile extends React.Component { render() { const { name, avatar } = this.props; return ( <div className="player

Passing props into external stylesheet in React Native?

孤者浪人 提交于 2019-11-30 03:02:55
问题 I'm new to React and React Native. At the moment for each component I'm breaking the code into 2 separate files: index.js for all the React code, and; styles.js for the StyleSheet Is there a way to pass props into the external StyleSheet? Example: index.js : render() { const iconColor = this.props.color || '#000'; const iconSize = this.props.size || 25; return ( <Icon style={styles.icon} /> ); } Example styles.js : const styles = StyleSheet.create({ icon : { color: iconColor, fontSize:

Babel 6 react JSX transformer - disable strict

荒凉一梦 提交于 2019-11-30 01:12:15
问题 Issue I'm using babel 6 for react JSX transforms. However I'm not using the react preset, I am ONLY using the 'transform-react-jsx' plugin (and trying strict-mode disable option), here is my .babelrc { "plugins": [ ["transform-react-jsx"] ], "sourceMaps": true, "strictMode": false } However I have required a thirdparty javascript that uses 'with' (out of my control) which emits following error: [SyntaxError: foo.js: 'with' in strict mode .. ] So I need to disable strict mode, This is same

How to make IntelliJ IDEA resolve webpack requires out of node_modules directory?

非 Y 不嫁゛ 提交于 2019-11-30 00:45:11
问题 IntelliJ cannot resolve javascript modules called with webpack requires which are not inside the node_modules directory Imagine this project structure: `- project |- node_modules | `- react | `- addons.js |- webpack.config.js |- util | `- tool.js `- src |- components | `- uno.jsx `- two.jsx This is my webpack config // webpack.config.js var path = require('path'); module.exports = { resolve: { root: [ path.resolve('./src'), path.resolve('./') ] } ... } And this is how I use webpack's require

React onClick event

人盡茶涼 提交于 2019-11-30 00:43:42
问题 I'm missing something. Here's a very simple hello world, the goal is to just fire an alert event onClick. The event does fire when the page loads, but not when I click the button. I appreciate the help. Here's a jsFiddle to make it easier to see: jsFiddle var Hello = React.createClass({ render: function() { return <button onClick={alert("Hello World!")}> Click Me </button>; } React.render(<Hello />, document.getElementById('container')); 回答1: I think you're going about this wrong, because