you need to get function with the index you found;
var func = functions.indexOf(options.indexOf(this.state.type));// this returns index not the actual func
functions[func] && functionsfunc
My Approach would be like;
getBTC = () => {
// .....
};
getETH = () => {
// .....
};
getADA = () => {
// .....
};
getCoin = (type) => {
switch(type) {
case "BTC": this.getBTC()
return
case "ADA":...
...
...
}
componentDidMount() {
this.getCoin(this.state.type)
}
Answer from ilkerkaran on Stack OverflowW3Schools
w3schools.com › react › react_es6_array_methods.asp
React ES6 Array Methods
One of the most useful in React is the .map() array method. The .map() method allows you to run a function on each item in the array, returning a new array as the result.
14:30
React tutorial in Hindi #33 Array Listing with Map function - YouTube
27:07
#9 React Native Array Map Function - YouTube
Comprehensive Guide to Rendering an Array in React with ...
11:22
React tutorial for beginners #33 Array Listing with Map function ...
05:55
React Hooks Tutorial - 5 - useState with array - YouTube
DEV Community
dev.to › jamesncox › array-methods-33ii
Array Methods - DEV Community
April 29, 2021 - When working with React, you often render specific data based on specific needs/requirements. Like we saw with filter(), we rendered <p> tags of fruits that met a certain requirement. Similarly, you may want to show only the first matching item from an array. In the Codesandbox, under the ".find()" tab, I copy/paste the input form and functions ...
W3Schools
w3schools.com › react › react_es6_array_map.asp
React ES6 Array map()
Note: When using map() in React to create list items, each item needs a unique key prop. ... const users = [ { id: 1, name: 'John', age: 30 }, { id: 2, name: 'Jane', age: 25 }, { id: 3, name: 'Bob', age: 35 } ]; function UserList() { return ( <ul> {users.map(user => <li key={user.id}> {user.name} is {user.age} years old </li> )} </ul> ); } ... const fruitlist = ['apple', 'banana', 'cherry']; function App() { return ( <ul> {fruitlist.map((fruit, index, array) => { return ( <li key={fruit}> Name: {fruit}, Index: {index}, Array: {array} </li> ); })} </ul> ); }
Pluralsight
pluralsight.com › blog › tech guides & tutorials
Manipulating Arrays and Objects in State with React | Pluralsight
November 4, 2020 - With the introduction of hooks in React 16.8, functional components can now also handle state in a simplified way. The snippet below is the class-based <MyComponent/> written as a functional component. The useState hook is a function that takes in a default value as a parameter (which can be empty) and returns an array containing the state and a function to update it.
DEV Community
dev.to › 04anilr › array-methods-in-reactjs-36jb
Array methods in react.js - DEV Community
March 19, 2024 - Math.max() and Math.min() functions along with the spread operator (...) to find the maximum and minimum values, respectively. We render the results within JSX, displaying the original array, sum, average, maximum, and minimum values. This component, when rendered, will display the array, sum, average, maximum, and minimum values calculated from the array of numbers. Remember that React components are just JavaScript functions, so you can perform any JavaScript operations within them, including mathematical operations on arrays.
React
react.dev › learn › rendering-lists
Rendering Lists – React
Arrow functions containing => { are said to have a “block body”. They let you write more than a single line of code, but you have to write a return statement yourself. If you forget it, nothing gets returned! Notice that all the sandboxes above show an error in the console: ... Warning: Each child in a list should have a unique “key” prop. You need to give each array item a key — a string or a number that uniquely identifies it among other items in that array:
Scott Bolinger
scottbolinger.com › home › 5 critical javascript methods you need to know for react
5 Critical Javascript Methods You Need To Know For React - Scott Bolinger
June 10, 2021 - You can also get the index and original array in your callback function. const arr = [1,2,3,4]; const newArr = arr.map( (val, index, arr) => val + index ); console.log(newArr) // 1,3,5,7 · Map does not change the original array. ... In React, you commonly see it used to display an array of objects.
React
legacy.reactjs.org › docs › lists-and-keys.html
Lists and Keys – React
We can use the same keys when we produce two different arrays: function Blog(props) { const sidebar = ( <ul> {props.posts.map((post) => <li key={post.id}> {post.title} </li> )} </ul> ); const content = props.posts.map((post) => <div key={post.id}> <h3>{post.title}</h3> <p>{post.content}</p> </div> ); return ( <div> {sidebar} <hr /> {content} </div> ); } const posts = [ {id: 1, title: 'Hello World', content: 'Welcome to learning React!'}, {id: 2, title: 'Installation', content: 'You can install React from npm.'} ]; const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<Blog posts={posts} />);
React
react.dev › learn › updating-arrays-in-state
Updating Arrays in State – React
There are multiple ways to do this, but the easiest one is to use the ... array spread syntax: ... import { useState } from 'react'; let nextId = 0; export default function List() { const [name, setName] = useState(''); const [artists, setArtists] = useState([]); return ( <> <h1>Inspiring sculptors:</h1> <input value={name} onChange={e => setName(e.target.value)} /> <button onClick={() => { setArtists([ ...artists, { id: nextId++, name: name } ]); }}>Add</button> <ul> {artists.map(artist => ( <li key={artist.id}>{artist.name}</li> ))} </ul> </> ); }
Medium
medium.com › @johnsonzagazor06 › understanding-the-basics-of-map-and-arrays-in-react-d380f37764bc
Understanding the Basics of map() and Arrays in React | by Okafor Johnson | Medium
September 10, 2024 - Inside the return statement, we use the map() method to iterate over the fruits array. For each fruit, we create an <li> element and assign a unique key prop (here, using the index, but it's better to use a unique identifier if available). ... Let’s enhance our example by rendering a list of fruit objects that contain both names and colors. ... import React from 'react'; const FruitList = () => { const fruits = [ { id: 1, name: 'Apple', color: 'Red' }, { id: 2, name: 'Banana', color: 'Yellow' }, { id: 3, name: 'Cherry', color: 'Red' }, { id: 4, name: 'Date', color: 'Brown' }, ]; return ( <div> <h2>Fruit List</h2> <ul> {fruits.map((fruit) => ( <li key={fruit.id}> {fruit.name} - <span style={{ color: fruit.color }}>{fruit.color}</span> </li> ))} </ul> </div> ); }; export default FruitList;
Robin Wieruch
robinwieruch.de › react-state-array-add-update-remove
How to manage React State with Arrays - Robin Wieruch
May 17, 2020 - Similar to the other array methods, the filter method uses a function as argument that determines whether an item stays in the array or gets removed. There is another neat little trick for one case: If you want to remove the first item in an array, you can do it with the array destructuring operator. Let’s see how you can remove the first item of an array on a button click. ... import React, { Component } from 'react'; class App extends Component { constructor(props) { super(props); this.state = { list: [42, 33, 68], }; } onRemoveFirstItem = () => { this.setState(state => { const [first, ...rest] = state.list; return { list: rest, }; }); }; render() { return ( <div> <ul> {this.state.list.map(item => ( <li key={item}>The person is {item} years old.</li> ))} <button type="button" onClick={this.onRemoveFirstItem}> Remove First Item </button> </ul> </div> ); } } export default App;
ReScript
rescript-lang.org › docs › react › latest › arrays-and-keys
Arrays and Keys | ReScript React
We can use the same keys when we produce two different arrays: ... type post = {id: string, title: string, content: string} module Blog = { @react.component let make = (~posts: array<post>) => { let sidebar = <ul> {Array.map(posts, post => { <li key={post.id}> {React.string(post.title)} </li> })->React.array} </ul> let content = Array.map(posts, post => { <div key={post.id}> <h3> {React.string(post.title)} </h3> <p> {React.string(post.content)} </p> </div> }) <div> {sidebar} <hr /> {React.array(content)} </div> } } let posts = [ { id: "1", title: "Hello World", content: "Welcome to learning ReScript & React!", }, { id: "2", title: "Installation", content: "You can install @rescript/react from npm.", }, ] let blog = <Blog posts />