score:1
You can use one object to contain two states like this:
import { useEffect, useState } from 'react';
import axios from 'axios';
const App = () => {
// use one object to contain two states
const [data, setData] = useState({ dataOne: '', dataTow: '' });
// fetch data
useEffect(() => {
const fetchData = async () => {
const dataOne = await axios.post(URL1, inputValue, {
headers: { 'Content-Type': 'text/plain' },
});
const dataTow = await axios.post(URL2, inputValue, {
headers: { 'Content-Type': 'text/plain' },
});
setData({ dataOne, dataTow });
};
fetchData();
}, []);
// display data
return (
<TableContainer>
<Table>
<TableHead>
<TableRow>
<TableCell>Dessert (100g serving)</TableCell>
<TableCell align="right">Calories</TableCell>
<TableCell align="right">Fat (g)</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableCell>{data.dataOne}</TableCell>
<TableCell>{data.dataTow}</TableCell>
</TableBody>
</Table>
</TableContainer>
);
};
export default App;
I hope it helpful.
Source: stackoverflow.com
Related Query
- How to map over 2 Array of object in React and render to Table
- How to map over 2 Array in React and render to Table
- How do I map over an array of objects in React and then conditionally render a component based on a previous value?
- How do I get the "results" object nested in the array "news" and map over it?
- Filter and map over updated array and render in table
- how to map over an Object and render the arrays inside the object javascript/reactjs?
- In React How can I fetch data and render a single object in a states array without mapping the whole thing?
- How can I shuffle an array of objects on page render and map over the shuffled array without console warning of "two children with the same key"?
- React - map over array object and pass to options prop in react-select
- How to map over an object which has a unique id for each object values and return the values to a React component
- How to render an object from an array in MongoDB and react
- Use map function for array object and display in table in React
- How to render and map an object using a variable as a key in react
- How to create React elements in an array (with props) and then render them by simply mapping over that array?
- How to use for loop in react so I can loop over two array and return the object in second array if both match
- How to render react components by using map and join?
- How to handle object and Array in react native?
- React: How to convert JSON Object to Array and render it?
- How to find object in array and show it in React component?
- How do i iterate over an array of object in react.js and add the values of prices in the object as shown below
- REACT JS: Map over an array of objects to render in JSX
- How do I map my Union typed GraphQL response Array in React and Typescript
- How to fix my React Context to render useEffect and reload table data
- how to map an array of images and use it as inline style in React
- How to render multiple buttons by iterating over an array in React
- How to iterate over an array that's inside an object in React JS
- How to make a react table whose rows and columns come from a JSON object
- how should we convert string data into array and display into react table
- How can I conditionally render elements with React and Firebase via map function?
- How can I render the contents of an array nested inside an object in React Admin's show/ArrayField component?
More Query from same tag
- Conditional IF statement inside this.state of the Constructor Reactjs
- React / mxGraph: How to render Graph from external source, with functional react component?
- Loading Muicss styles in React js
- Gradient fill for react-highcharts' line chart
- How do I generate random buttons based on my data coming from API request?
- Listen for a specific Store property change
- React Component Not Updating After Changing A Value
- KeyboardDatePicker grayout days
- 404 Not Found Next.js error on React-Query fetch
- How to use apolloClient's 'onSuccess' only once the useMutation has executed successfully
- Heavily customising Material UI DataTable (React)
- Is it possible to serve different versions of a static page with nextjs on vercel according to useragent (device type)?
- Having this error in the console Each child in a list should have a unique "key" prop
- Radium-React reports "please wrap your application in the StyleRoot component" when using MediaQuery
- How to pass value to modal using React.js?
- Calling useState hook in child - state data is empty
- How to change only the one value of a object in a state
- How to obtain the timezone from open weather map and use it as a parameter using Vailla JS
- Display Firestore Data with a datatype of map: Error: Objects are not valid as a React child
- How to confirm if ES6 is being used (ReactJS + Redux)
- How to display only first two object in JavaScript?
- How to deal with local storage and SSR?
- React Native project do not have index.ios.js or index.android.js
- Mapping to React Modal renders all items from array instead of mapping by their ID
- All indices are console logged immediately after rendering - React
- Jest fails Cannot find module 'react/lib/React' from 'ReactShallowRenderer.js' after React 16 upgrade
- React react-router-dom pass props to component
- Component is not rendering with react-router
- ComponentWillMount trigger not stop?
- Passing a custom class/style to a styled-component in Gatsby (React)