React: How to call a parent function from a child function and/or pass data to the parent function

In a continuation of the theme of how to pass information around in react, this article details how to call a parent function from a child function. This previous article details how to pass state from parent to child: React: How to pass state information from parent to child Allowing a child function to call … Continue reading React: How to call a parent function from a child function and/or pass data to the parent function

React: How to pass state information from parent to child

In a react script, to pass state information from a parent component to a child component, the state information needs to be passed as a prop. For example: numturns={this.state.number_of_turns} Now, “numturns” can be used as a prop in the child. For example, inside the child handleclick function: console.log(“Child communication, number of turns from parent: “, … Continue reading React: How to pass state information from parent to child

React: Using .bind(this) on parent and child components

In a react script, for every function in both the parent and child components we must have this magic line using .bind(this)in the constructors: this.nameOfFunction = this.nameOfFunction.bind(this); For example: // Parent with a incrementNumberTurns() function: this.incrementNumberTurns = this.incrementNumberTurns.bind(this); // Child with a handleClick() function: this.handleClick = this.handleClick.bind(this) Here is an example from the parent component … Continue reading React: Using .bind(this) on parent and child components

JavaScript: How to get the largest number in an array using Math.max( )

If we want the largest one number in an array, we can get that using JavaScript’s  Math.max() function. Simply place the array of values (without square brackets) into the parenthesis of the function. Like so: console.log(Math.max(1, -5, 2, 8, 17, 0, -2)); Which yields: 17 A list of all negative numbers: console.log(Math.max(-11, -8, -2)); Which … Continue reading JavaScript: How to get the largest number in an array using Math.max( )