Skip to content

Tag: reactjs

react.js Replace img src onerror

I have a react component that is the detail view from a list. I am trying to replace the image with a default image if the image does not exist and there is a 404 error. I would normally use the onerror method in the img tag but that doesn’t seem to be working. I am not sure how to

update nested object with (ES6) computed property name

In my case, I’m using React.js and I would like to dynamically update the values in the deployOptions object. For example – initial state looks like: Obviously this is not correct – but this is what I’m trying to achieve so that my state would then be Answer It’s not especially p…

Can’t type in React input text field

I’m trying my first bit of React.js and am stumped early on… I have the code below, which renders a search form into <div id=”search”></div>. But typing in the search box does nothing. Presumably something is going missing passing the props and state up and down, and this s…

react componentDidMount not firing

I set up a new react project and for some reason, the componentDidMount method is not being called. I have verified this behavior by placing a call to console.log in componentDidMount but I cannot see its output in the console. Furthermore, this.setState() is not working. I’m pretty stumped as to why th…

How to access canvas context in React

I made a color picker with React and Canvas. Currently the components are rendered in React and canvas is done with vanilla javascript. I’d like to two to mesh more, so I want the click events to be handled with React. For example, this I would hope would be able to translate to this But that doesn&#821…

Detect click outside React component

I’m looking for a way to detect if a click event happened outside of a component, as described in this article. jQuery closest() is used to see if the target from a click event has the dom element as one of its parents. If there is a match the click event belongs to one of the children and is thus