FAQ Database Discussion Community


ReactJs tries to attach onclick handler before Ajax loads element

javascript,ajax,reactjs
I am creating a dynamic list for a menu in ReactJs. The data for each menu item is bing pulled in from a JSON file via AJAX. I want the menu to close when a menu item is clicked. I am giving the whole list the prop "whenClicked" when one...

How can I get simulated react events to update the values of the ref in my component?

javascript,unit-testing,testing,reactjs,reactjs-testutils
So I have a react component that looks something like this: class SignInForm extends React.Component { constructor(props) { super(props); } onFormSubmit(event) { const username = React.findDOMNode(this.refs.username).value; const password = React.findDOMNode(this.refs.username).value; // very basic validation if (username && password.length > 6) { this.props.flux.signIn({ username, password }); } event.preventDefault(); } render() {...

JQuery .animate() not working with ReactJS?

jquery,reactjs
I am trying to highlight a cell when the user click on it by using jQuery .animate() clickHandler: function() { var cell = React.findDOMNode(this.refs.cell); // $(cell).css("background-color", "blue"); // THIS WORK $(cell).animate({ backgroundColor: "blue" }, 1000); // THIS DOESN'T WORK }, I am also using React.addons.CSSTransitionGroup. Maybe there is a conflict...

How to access nested object in React js 0.13.3

javascript,jquery,html,reactjs
The below added code is working fine in React js 0.10.0. I wanna run same code in 0.13.0 version also. My main requirement is accessing nested object as default object like "this.state.data.query.results.channel.item.condition.temp". <!doctype html> <html> <head> <title>Weather Widget</title> <link rel="stylesheet" href="weather.css" /> <script src="http://fb.me/react-0.10.0.js"></script> <script src="http://fb.me/JSXTransformer-0.10.0.js"></script> <script...

reactjs Uncaught TypeError: Cannot read property 'map' of undefined

javascript,jquery,ajax,reactjs
I have used getInitialState on my BrowseWidgetBox component. Although when passing the data to my MainMenu component, the data remains empty, as if the AJAX call to the api was never run in the BrowseWidgetBox. My question then, is why is this happening? Shouldn't componentDidMount call the ajax api and...

Better/faster way for changing React array state than cloning it?

reactjs
Whenever a React class has a state object that is or contains an array, updating that state feels awkward. Usually what I do is var newArrayThing = _.clone(this.state.arrayThing); //or slice() newArrayThing[123] = 42; //update stuff this.setState({arrayThing: newArrayThing}); Is there a better or more elegant way of handling this I am...

html Forms inside reactJS

javascript,html,reactjs
I used the (almost) exact syntax for creating an html form in react: var Hello = React.createClass({ render: function() { return <div> <section> <form action="http://localhost:9203/ask"> Text: <input type="text" name="text" value="Text"/> <br/> Focus: <input type="text" name="focus" value="Focus"/> <br/><br/> <input type="submit" value="Submit"/> </form> </section> </div>; } }); React.render(<Hello name="World" />, document.getElementById('container'));...

Canvas element does not resize when using ReactJS and PaperJS together

javascript,html,canvas,reactjs,paperjs
I have found that canvas elements correctly resize on window resize when they are inside react components. They also resize correctly when used with PaperJS. However, they do not resize when used with PaperJS and ReactJS together. Is this an incompatibility between PaperJS and ReactJS or am I instantiating PaperJS...

Do I have to call super.componentDidUpdate in React?

reactjs,ecmascript-6
In a subclass of React.Component, do I have to call super.componentDidUpdate from my componentDidUpdate method? Or is it done automatically? (I am trying to call it but there is an error message Cannot read property call of undefined)...

defaultValue change does not re-render input

reactjs
I have no idea why this is not working Demo I have the following es6 code const {createFactory, createClass, DOM: { label, input, button }} = React; const tester = createFactory(createClass({ render() { return label({} ,`Name: ${this.props.name}` ,input({defaultValue: this.props.name}) ,button({onClick: this.changeName}, "Change") ) }, changeName() { this.setProps({name: "Wilma"}) } })...

React Rails component: manually triggering a re-render

javascript,jquery,ruby-on-rails,reactjs,react-rails
In Rails, I've got a set of Bootstrap tabs on a page with a React component on each one, ie: <div id="tab-1" class="tab-pane"> ... <%= react_component('PeopleWidget', person_id: @person.id) %> ... </div> <div id="tab-2" class="tab-pane"> ... <%= react_component('ContentWidget', content_id: @content.id) %> ... </div> The components: Do not talk with each other...

React animation / ReactCSSTransitionGroup

reactjs
How would you make the following link - a spinner - work with reactjs http://codepen.io/awesome/pen/znGwr I am using webpack: { test: /\.css$/, loader: "style-loader!css-loader" } I know the css is working from other settings. I have tried the following, using the same css file(copy paste into local css ). Updated:...

React Flux dispatcher vs Node.js EventEmitter - scalable?

node.js,design-patterns,reactjs,flux,eventemitter
When you use Node's EventEmitter, you subscribe to a single event. Your callback is only executed when that specific event is fired up: eventBus.on('some-event', function(data){ // data is specific to 'some-event' }); In Flux, you register your store with the dispatcher, then your store gets called when every single event...

Nesting in Default Route

javascript,reactjs,react-router
I have an applications index page that lists all my applications. The index page is also the default route. I want to nest a 'applications new' modal in the index page. This way I can render the modal while on top of the index page. However, I'm not able to...

react-native this.setState not working

reactjs,react-native
I know there's already a similar question but there's no code shared in there. Under navbarChanged() > if condition, I'm doing a this.setState. This is of type HomeTab but setState doesn't seem to be working. Any clues/pointers? class HomeTab extends React.Component { constructor() { super() this.setState({ isNavBarHidden: false }); }...

Multiple React components in a single module

reactjs,gulp,browserify
I am new to the whole browserify thing. I have been trying to use browserify + reactify + gulp to transform, minify and combine a React application. As long as I have a single React.createClass with a single module.exports = MyComponent everything works fine. Since I have several shared components...

React - saving a component in the ref callback

reactjs
So, extract from https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute The ref attribute can be a callback function instead of a name. This callback will be executed immediately after the component is mounted. The referenced component will be passed in as a parameter, and the callback function may use the component immediately, or save the reference...

Dynamic key in immutability update helper for array

javascript,reactjs,ecmascript-6
https://facebook.github.io/react/docs/update.html I have an update function that receives an index along with the event so as to alter the value for that specific item in the array. How do I get index to be evaluated instead of treated as a set key in this scenario? Is it even possible? updateValue:...

react-router link to sub route

javascript,reactjs,react-router
How do I create a link for sub route like lang -> python ? My routes var routes = ( <Route name="app" path="/" handler={ App }> <Route name="info" handler={ Info } /> <Route name="home" handler={ Home } /> <Route name="lang" handler={ Lang } > <Route path="java" handler={Lang}/> <Route path="python" handler={Lang}/>...

react server side rendering with client side routing

javascript,reactjs,single-page-application,isomorphic-javascript
An initial server rendering for my homepage route ( / ) works fine. Also, subsequent client side navigation to ( /#/page2 ) works fine. However, if I load /#/page2 directly from the address bar, the server rendered homepage loads in the browser first and then visibly transitions to /#/page2, which...

React components as plain JS objects?

javascript,class,reactjs,javascript-objects,ecmascript-6
Does anybody has experience in working with React components as plain JS objects instead of annoying ES6 classes and deprecated .createClass method. Maybe you have some examples of factory functions or similar to share? Thanks!...

Django Rest Framework + React + Reflux: Can't GET new objects

django,reactjs,django-rest-framework,refluxjs
I'm trying to post a new object via a React form using a Reflux action. That part is working fine. The object is posting as expected, however, when I try to GET that object programmatically, it doesn't seem to be accessible unless I log out, restart my local server, or...

Jest - How to find rendered DOM component with id?

reactjs,jestjs
I am writing a simple Jest test that verifies that my component rendered. I see that React's TestUtils has functions for finding rendered components by class or by tag, but not by their ID attribute. There is a findAllInRenderedTree function, but the documentation does not explain what the callback should...

How to append to dom in React?

javascript,reactjs
Here's a js fiddle showing the question in action. In the render function of a component, I render a div with a class .blah. In the componentDidMount function of the same component, I was expecting to be able to select the class .blah and append to it like this (since...

Reactjs - the spread operator giving error

javascript,reactjs,react-jsx
I am trying to use the spread operator in react.js but getting the error Unexpected token ... in Chrome. I am getting an error at the line 3 in this code: var Btn=React.createClass({ render: function(){ var { className, ...other }=this.props; return (<a {...other} className={joinClasses(className,"btn")} href="#" >{this.props.children}</a>); } }); and using...

Can I use Backbone with React Native?

javascript,ios,backbone.js,reactjs,react-native
I have found several different examples of integrating React (View) with Backbone on the web, but not any to do the same with React Native. I was wondering if this was possible and also if there were any samples to play with. This (https://github.com/magalhas/backbone-react-component) also seemed a good starting point,...

Encapsulation with React child components

coding-style,reactjs,encapsulation
How should one access state (just state, not the React State) of child components in React? I've built a small React UI. In it, at one point, I have a Component displaying a list of selected options and a button to allow them to be edited. Clicking the button opens...

ReactJS - Custom Dropdown

reactjs
I have a drop down that has a nested ul in ECMAScript 6. Relevant code for dropdown: ...... handleItemClicked(item){ alert(item) } render(){ return( .... <UnorderedList whenItemClicked={this.handleItemClicked} /> .... ) } Relevant code for unordered list: return( <ul> .... {this.props.dropItems.map(function(item){ return (<li onClick={this.props.whenItemClicked(item)} key={item}><a>{item}</a></li>) }, this)} </ul> ) Result: There are...

Input validation setTimeout in ReactJS

javascript,css,validation,reactjs,ecmascript-6
I have a component that renders with className="error" or classname="" depending on whether the input is valid or not. This way in CSS I can simply do .error { background: red; }. The validity of the input is determined by the isValidNumber(..) function. However, right now the problem I'm having...

Ajax success issue with React and Rails

ruby-on-rails,ajax,reactjs
I've got a form that I am trying to handle with React. This is the ajax method in the handleSubmit function: $.ajax({ data: formData, dataType: "json", url: '/requests', type: "POST", success: function(data, status, xhr) { console.log('SHOW HERE ON RESPONSE'); this.setState({ formSubmitted: true }); } }); When I click on submit,...

JS - How to update DOM in realtime across multiple instances of the same web app?

javascript,jquery,reactjs,ractivejs,real-time-updates
I am building a massive real-time collaboration web application. It is a Web IDE that has support for HTML, CSS & JS programming and a stage area that would reflect the results a la JSFiddle, Plunker etc. Now, the twist is that, it would support multi-user real-time collaboration, where people...

React page layout using react-router

javascript,reactjs,react-router
I have a default layout page here using react router: Header = require('./components/Header'), Footer = require('./components/Footer'), var sampleApp= React.createClass({ getDefaultProps() { return { title: 'Page One' }; }, render: function (){ return ( <div className="app"> <Header title={this.props.title} /> <RouteHandler /> <Footer /> </div> ); }, }); var routes = (...

ReactJS component not rendering textarea with state variable

javascript,textarea,reactjs
I am facing an intriguing bug in React. I have this component: 'use strict'; import SummaryStore from '../stores/SummaryStore'; import React from 'react'; export default class ChangeSummaryForm extends React.Component { constructor() { // store initialisation SummaryStore.register(); var vRating = SummaryStore.getBookForSummaryPrint().summaryRating; var vStarClassName = this.getRatingClasses(vRating); this.state = { sStarClassName: vStarClassName, sCurrentBookToShow: SummaryStore.getBookForSummaryPrint()...

Dynamic className in cjsx

coffeescript,reactjs
I am trying to hide a component and update the image in a button when I click said button. I have managed to hide the component by doing the follow: {<MyAwesomeComponent /> unless @state.hide} And I change the state by doing: toggleComponent = -> @setState hide: [email protected] . . ....

React Component with subcomponents or render HTML in parent?

reactjs
I have a question regarding React patterns. When rendering a component, is it appropriate for this component to render several sub-components, or is it ok to render some HTML in the parent component. Example: If I have a box that has a heading and a body with list of elements,...

Page update when clicking a button (reactjs)

javascript,reactjs
Suppose I want to render page again, after clicking a button. How can I accomplish it? In particular how would you change my program to generate random texts, when clicking the button? var colors = ['red', 'yellow', 'blue', 'green']; var Hello = React.createClass({ randomText(color) { var style = { color:...

Iterate over all refs values in component

javascript,reactjs,jsx,react-jsx
I am trying to access all ref values in my component and do something with them (for example, create payload to send to a server) I was trying to do a simple for..in loop and than use getDOMNode().value on every ref but it doesn`t work. var Hello = React.createClass({ getAllRefsValues:...

Hide context menu on outside click

javascript,reactjs
I have a context menu that appears when you right click inside the <div>, and it only goes away if the user click left click inside the <div> again. How do i hide it when a user click anywhere on the page? my fiddle...

ReactJS: How to optimise top-down render flow

javascript,reactjs,scalability,reactjs-flux
Looking at Facebook's Flux TodoMVC example (https://github.com/facebook/flux/tree/master/examples/flux-todomvc/) makes me wonder how this approach scales. In the example the store is updated onBlur/Enter keypress of a new entry, but what if we wanted to update an existing entry on keypress? i.e. you type something in an input and this is persisted...

ReactJs w/ ECMAScript 6

reactjs
I have the follow component (radioOther.jsx): 'use strict'; //module.exports = <-- omitted in update class RadioOther extends React.Component { // omitted in update // getInitialState() { // propTypes: { // name: React.PropTypes.string.isRequired // } // return { // otherChecked: false // } // } componentDidUpdate(prevProps, prevState) { var otherRadBtn =...

Should I pass all the state in every change from store to component?

javascript,performance,reactjs,reactjs-flux,flux
I am new on React and Flux and I am making an app that will have an input (like the name or the title), and below a list of n things. How should I handle the event listeners? I saw in the TODO example of flux (https://github.com/facebook/flux/blob/master/examples/flux-todomvc/) that they use...

Adding resolver to React-router

reactjs,react-router,refluxjs
In react-router, is there any way to pass a property from the Route-definition that can be picked up within the Router.run function? I want specific actions to fire for specific routes. Something like this perhaps: <Route handler={someComponent} resolve={someAction} /> In Router.Run i want to execute that given action defined in...

react-router go back a page how do you configure history?

javascript,reactjs,react-router
Can anyone please tell me how I can go back to previous page rather than a specific route? When using this code: var BackButton = React.createClass({ mixins: [Router.Navigation], render: function() { return ( <button className="button icon-left" onClick={this.navigateBack}> Back </button> ); }, navigateBack: function(){ this.goBack(); } }); Get this error, goBack()...

Trying to understand how an isomorphic react app is supposed to do client-side routing

reactjs,client-side,isomorphic-javascript
Pardon my English, it is a second language. The whole point of an isomorphic app, as opposed to a regular client-side SPA is so the client doesn't have to download the whole JS file initially which results in really slow initial load time. I've been trying to teach myself server-side...

props is not initialized in react component

reactjs,flux
I have developed a Component. In it, I am loading the data based on an Id which is passed to it like; my Item Component code looks like ItemStore.CallItem("TenantId",this.props.MetaItemId); and my calling page code looks like <div className="box-body table-responsive no-padding list-relations" id="configureMM"> <Item MetaItemId={11} /> </div> <div className="box-body table-responsive no-padding...

Using react-router and express with authentication via Passport.js - possible?

javascript,node.js,express,reactjs,passport.js
So I'm working on a project that incorporates React, Express.js+Passport and Webpack. I understand the concept of pushing everything to a 'master' React component via react-router, then letting it hash out what gets displayed for the given route. That would work great here, I think. To be upfront, I am...

difference between componentDidMount and getInitialState in Reactjs

facebook,reactjs,flux
I understand that getInitialState is called once in the component's lifecycle and componentDidMount is called when the component is rendered. So does that mean both will get called just once in the component's lifecycle? What's the difference?...

Why is my setState is not working? [duplicate]

javascript,reactjs
This question already has an answer here: Using a variable for a key in a JavaScript object literal 3 answers I have a react component that I have created. In this component, I call a function that updates the state generically: updateCheckbox: function(name, value) { this.setState({name: value}); }, I...

list not ordering well dynamic children

reactjs
My problem is that react is not respecting the order I am giving by the backend. It gives me a warning. Child objects should have non-numeric keys so ordering is preserved I checked the documentation and I don't know where the error is. dynamic children I'm passing the key to...

Why calling react setState method doesn't mutate the state immediately?

javascript,reactjs,react-jsx
I'm reading Forms section of reactjs documentation and just tried this code to demonstrate onChange usage (JSBIN). var React= require('react'); var ControlledForm= React.createClass({ getInitialState: function() { return { value: "initial value" }; }, handleChange: function(event) { console.log(this.state.value); this.setState({value: event.target.value}); console.log(this.state.value); }, render: function() { return ( <input type="text" value={this.state.value} onChange={this.handleChange}/>...

ReactJS - how to use comments

reactjs
Can you not use comments inside the render method? I have the following component: 'use strict'; var React = require('react'), Button = require('./button'), UnorderedList = require('./unordered-list'); class Dropdown extends React.Component{ constructor(props) { super(props); } handleClick(){ alert('I am click here'); } render(){ return( <div className="dropdown"> // whenClicked is a property not...

conversion of string to JSON object in javascript with eval() [duplicate]

javascript,reactjs
This question already has an answer here: Eval() = Unexpected token : error 7 answers I am converting the following JSON variable to string, and back to JSON, and getting error (in ReactJS, although it shouldn't be important) var questionGlobal = { "questionCons": [{ "string": "In", "alignment": 2 },...

TypeError: this.props.data.map is not a function, but data is a list

javascript,reactjs
I have written code from the ReactJs site here while working through their comment box tutorial. Yet for some reason it is giving me an error about map: Uncaught TypeError: this.props.data.map is not a function Specifically it is complaining about line 7: var commentNodes = this.props.data.map(function (comment){ .. etc.. }...

Changing the state of a component that isn't directly handling the event in ReactJs

javascript,reactjs
To better understand my question, take a look at my component diagram: https://app.box.com/s/rkq9bhyzs00971x6xgpq8exmvu4zzjlt By looking at the image, you can see I essentially have a component structure of Browse Widget -Main Menu -Display -SubMenu -SubCategory -SearchBar -Video Display My Display Component houses all the components that pull from an API....

How to test interactivity of React component using D3 select()?

javascript,svg,d3.js,reactjs
I have a React visualization component (Using SVG) that displays a tooltip on mouseOver, using the d3.select() function to modify a class on the tooltip element so that it becomes visible (And invisible on mouseOut): _handleMouseOverEvent: function() { d3.select('#' + this.props.caption).classed('hidden', false); d3.select('#' + this.props.caption).classed('visible', true); } _handleMouseOutEvent: function() {...

Reactjs this.state giving Uncaught TypeError: Cannot read property 'groupsData' of null

javascript,ajax,reactjs
I am doing 2 basic ajax calls to 2 different apis in one of my ReactJs components. Although, when running the call (on urls I know for certain are working and returning data), I receive: Uncaught TypeError: Cannot read property 'groupsData' of null Here is the single component: var BrowseWidgetBox...

How do I load SVGs directly in my React component using webpack?

svg,icons,reactjs,loader,webpack
I would like to render a material design icon directly in my NextButton component using webpack. Here's the relevant part of my code: var NextIcon = require('material-design-icons/navigation/svg/production/ic_chevron_right_18px.svg'); var NextButton = React.createClass({ render: function() { return ( <Link to={this.props.target} className='button--next'> {this.props.label} {NextIcon} </Link> ) } }); But this isn't working as...

No call function of parent in Reactjs

javascript,jquery,ruby-on-rails,reactjs
I have two function in Reactjs. When function one call a function of function two. There have error same as "Uncaught TypeError: this.props.onButonShowClick is not a function" This is function one : var HiddenEdit = React.createClass({ _handleOnClick: function(e) { e.preventDefault(), this.props.onButonShowClick(true); }, render: function() { return (<span className="col-lg-2 btn-action-group"> <a...

Rx.js React extension testing stream and intermediate results

unit-testing,reactjs,rxjs
I have a module which stores data in this.store and takes keyboard events in this.stream The relationship between this.store and this.stream is as follows this.stream.subscribe(function(keyCode){ this.store.add(100) }); Now I am writing test cases against those events. I want to know when I click the keyboard 3 times respectively what will...

Get font color of ReactJS element

css,reactjs
I have a React component, a button, and I need to set the background-color of a child element to the color of the button. I know that you're not supposed to call this.refs.myElement.getDOMNode() in the render() function, so I'm not sure how I'm supposed to lay this out. At the...

Should every object in the store state be immutable?

javascript,reactjs,immutability,flux,immutable.js
I am learning React.js and Flux, and I understand that is better to keep the object immutable because comparing them is O(1). My situation is this: I have a store, which has a _state object, that is a map (I'm using Immutable-js). That _state has some booleans, some strings and...

Expected corresponding JSX closing tag for input Reactjs

javascript,reactjs,reactjs-flux,react-jsx
While creating a component in Reactjs with input fields error occurs Error: Parse Error: Line 47: Expected corresponding JSX closing tag for input at http://localhost/chat-react/src/script.js:47:20 </div> var Main = React.createClass({ render: function() { return ( <div className="card-action"> <i class="mdi-action-account-circle prefix"></i> <input id="icon_prefix" type="text" class="validate"> </div> ); } }); ...

React issue with updating state during re-render

javascript,reactjs
I have 2 components, a StaticComponent and an InteractiveComponent. The StaticComponent shows the user's information. It has a link to edit the information. That link has an onClick that fires off the handleEditClick function. This replaces the StaticComponent with an InteractiveComponent which has a form. var StaticComponent = React.createClass({ handleEditClick:...

React js css transitions on class removal

twitter-bootstrap,reactjs,css-transitions
I have column that should have different width depending on some flag. I use Bootstrap, so I assign col-xs-12 and col-xs-2 depending on the flag. Now I want it to change width slowly with css transition. I've read official React.js doc about transitions, but it doesn't apply to my case:...

What is the proper way to get the value of a React