score:0
Accepted answer
Ya I would make a component (or a function if that seems more appropriate) to render an individual coin.
You could make a <Coin>
component and pass the needed data to it as props:
render() {
return (
<div className='purse'>
{this.state.lists.map((coin, index) => <Coin data={coin} index={index} key={coin.CoinInfo.Id} />)}
</div>
);
}
Or just move the rendering of a coin to a new function:
renderCoin(coin, index) {
return <ul className='coin-containers' key={coin.CoinInfo.Id}>
<li><img className='coinImages' src={`${API_BASE_IMAGE}${coin.CoinInfo.ImageUrl}`} alt={coin.CoinInfo.FullName}/>
</li>
<li>{index + 1}</li>
<li>{coin.CoinInfo.FullName}</li>
<li className='ticker'>{coin.CoinInfo.Name}</li>
<li>{coin.DISPLAY.USD.PRICE}</li>
<li>{coin.DISPLAY.USD.SUPPLY}</li>
<li>{coin.DISPLAY.USD.MKTCAP}</li>
<li>24HR</li>
<li>{coin.DISPLAY.USD.CHANGEPCT24HOUR}%</li>
</ul>;
}
render() {
return (
<div className='purse'>
{this.state.lists.map((coin, index) => this.renderCoin(coin, index))}
</div>
);
}
Source: stackoverflow.com
Related Query
- Is this the correct way to show data in React from a fetch request, if not how do I change JSX being rendered to a component?
- How can I use react useContext , to show data from context, in the same component
- How to retrieve data from the server using fetch get method and show it in a table
- How to send data from react and use the request body in express, using Axios?
- How to take the result from a fetch request and insert data into jsx?
- How can I show 0 value in @nivo/bar graph, or is there any way to show No Data label if the value is 0 coming from api
- Does not show API fetch response data in the page - React Redux
- How to fetch data from server using JavaScript? (adding backend to React app for the first time)
- How do I use data from a Fetch request in the state?
- Is there any method to fetch the data from back-end MongoDB and show at front-end react JS?
- How to fetch image dynamically from database in React to show in the UI?
- What's the best way to do request multiple data from Firebase in React
- How do I display data fetched from firestore to a boostrap table in reactjs? I'm able to fetch but cannot display with the standard way of doing it
- Datatable did not show dynamic data which i fetch from database in react js
- How to add objects retrieved from fetch request to the state array in React and then update the view?
- Trying to figure out how to use socket.io the correct way in a useEffect that is using an axios get request to fetch messages
- I want to pass my fetch results to setState. When I console.log(setUserApartment) it doesn't show the data from foundApartment. How can I setState?
- How to avoid not to fetch the data from backend to frontend because of how many time component render?
- React component not displaying the correct data from Redux. Console log shows the correct data
- How to show image in react using the data from mysql created by xampp
- Is this the correct way to make an axios GET request with react redux?
- How to show an error message to the user in React when no data coming from API
- How to properly fetch data from several API calls and display it to the DOM in React
- How to fetch the new data in response to React Router change with Redux?
- Is there a right way to pass data into a React component from the HTML page?
- How to get the data from React Context Consumer outside the render
- How to fetch API data from Axios inside the getServerSideProps function in NextJS?
- React Select - How to show / iterate through data from api call in option instead of hardcoding options?
- How can I cache data that I already requested and access it from the store using React and Redux Toolkit
- How to fetch data in getInitialProps with redux-saga.Then get the response from redux store while in the getInitialProps method?
More Query from same tag
- How to set target in typescript to fromEvent() in rxjs
- React not rendering what is being returned by a function component
- Getting failed status while running jest test?
- TypeScript: make field public only for special classes
- Formik handleReset for spesific Select's with one value
- Record<string, any> to {name: string} in typescript
- store.getState is not a function
- Show different times based on day
- React how to pass a component with its props to another component
- React Router browserHistory.push open link in a new tab
- Accessing user uploaded images in a deployed MERN app
- Can I store these selected filters in a variable?
- NPM - Failed to replace env in config: ${NPM_TOKEN}
- How to save a nested object in state in React?
- Why I get 30 fps in chrome dev tool performance panel, but JS and React both say it's 60?
- What's the way to change state when scroll passes element?
- onLayoutChange is resetting my data from local storage
- Redux form and isomorphic-fetch always submits blank form to server
- React Router 1.0 How to redirect write redirect code inside flux action
- How do I set a state and revert it back to the previous state
- position:fixed is not working in the second part of div in react JS
- pushing object to array in reactjs?
- Child component still displays even though parent has height of zero
- Append to existing JSX instead of using if-else conditional logic
- Converting React class component to functional component with hooks : Problem with event listeners
- How to mock getFormValues for redux form
- One function to close a specified modal?
- How to convert MongoDB Buffer to Image in React/Node/Express
- React-How to display make objects loop in react
- D3.extent() throws TypeError : Values is not iterable