Update style of a component onScroll in React.js

I have built a component in React which is supposed to update its own style on window scroll to create a parallax effect. The component render method looks like this: function() { let style = { transform: ‘translateY(0px)’ }; window.addEventListener(‘scroll’, (event) => { let scrollTop = event.srcElement.body.scrollTop, itemTranslate = Math.min(0, scrollTop/3 – 60); style.transform = … Read more

React functional stateless component, PureComponent, Component; what are the differences and when should we use what?

Came to know that from React v15.3.0, we have a new base class called PureComponent to extend with PureRenderMixin built-in. What I understand is that, under the hood this employs a shallow comparison of props inside shouldComponentUpdate. Now we have 3 ways to define a React component: Functional stateless component which doesn’t extend any class … Read more

React won’t load local images

I am building a small react app and my local images won’t load. Images like placehold.it/200×200 loads. I thought maybe it could be something with the server? Here is my App.js import React, { Component } from ‘react’; class App extends Component { render() { return ( <div className=”home-container”> <div className=”home-content”> <div className=”home-text”> <h1>foo</h1> </div> … Read more

React-Native: Application has not been registered error

I am currently going through the React-Native tutorials. I began with the Getting Started tutorial, where I made a new react native project and successfully managed to run the project on my device. I then started the Props tutorial, I copied the code snippet and tried to run the project again and had the following … Read more

React: “this” is undefined inside a component function

class PlayerControls extends React.Component { constructor(props) { super(props) this.state = { loopActive: false, shuffleActive: false, } } render() { var shuffleClassName = this.state.toggleActive ? “player-control-icon active” : “player-control-icon” return ( <div className=”player-controls”> <FontAwesome className=”player-control-icon” name=”refresh” onClick={this.onToggleLoop} spin={this.state.loopActive} /> <FontAwesome className={shuffleClassName} name=”random” onClick={this.onToggleShuffle} /> </div> ); } onToggleLoop(event) { // “this is undefined??” <— here this.setState({loopActive: … Read more