score:2
Accepted answer
making the below changes produces the desired result:
- use find instead of filter in getproduto().
- correct typo in getprodutoadicionaischecked(). replace itensa with itens.
- modify getprodutos() as shown below. this code iterates over the products in the cart and for each product, fetches the product details, produtoopcoeschecked and produtoadicionaischecked returning all these data within a single object.
hence the method returns an array of objects, where object has the consolidated data for each product in the cart.
const getprodutos = () =>{
const produtoresult = produtoscart.map((item) =>
{
return {
// get the product data
...getproduto(item.id),
// get the options data
produtoopcoes: getprodutoopcoeschecked({groupid:item.idopcoesgroup,
idx: item.idopcoes}),
// get the additiones data
produtoadicionais: getprodutoadicionaischecked({groupid: item.idadicionaisgroup, idx: item.idadicionais})
}
}
);
return produtoresult;
}
Source: stackoverflow.com
Related Query
- What the best way to loading data to a cart react js with context api
- What is the best way to load and reuse api data for multiple routes in react
- What is the best way to store data with React Redux but by condition?
- What is the best way to deal with a fetch error in react redux?
- What is the best way to secure Firebase API keys in a react app so it is not accessible publicly?
- What is the best way to update my react state when data in database changes?
- What is the best way to save my dynamicly created data using React and Javascript?
- what is the best way to use react router V6 navigation with redux and redux thunk actions?
- What is the best way for connecting Django models choice fields with React js select options
- What is the best way to mutate remote data fetched with useQuery
- What is the best way to store previous response from an API and compare with new response in Nodejs?
- React - What is the correct way to make an API call with user input?
- What is the best way to structure api config file in react project?
- What is the correct way to React Hook Fetch Api and store to Redux and retrieve it with Selector immediately?
- With Moment.js - what is the best way to display a duration with modified locale data alongside a duration with default locale data?
- What is the best way to structure REST backend API calls with React?
- What is the best way to create a Loading Animation for React JS Ajax calls?
- With React what is the best way to handle conditional classes
- Best way to fetch data from a REST api using react hooks and context for state management?
- What are the pros and cons on using React Context API with the useReducer() hook?
- What is the best way to connect React js app with node js server?
- React Context API, Hook loading twice. Once without the data and once with the data
- What is the best way to define "KEY" in React when creating a list with map function from an array which containing no unique ID or fields?
- How do I use the Contentful api data with React Context API (useContext in particular)?
- What is the best way to build multi-language app with react and redux?
- What is the best way to switch between web app's themes with React & Redux?
- What are the best practices to initialize a Next.js webapp with data from an API and adding it to the state?
- What is the best way to compare two HTML pages with same data but different markup
- What is the best way to access redux store outside a react component?
- What is the best way to redirect a page using React Router?
More Query from same tag
- Node/React/Redux: having problems passing api JSON object between Node and React
- How to update an array in react using prevState?
- How to make input box readonly conditionally in React
- Importing the right files to use firebase's Realtime Database in React
- How will React 0.14's Stateless Components offer performance improvements without shouldComponentUpdate?
- How to package to 'production' my react website with Webpack?
- How to show the time when task was created by using react
- Can I pass a function (and get its ReturnType) to a generic TypeScript type?
- React testing library's waitFor() returns null
- Redux: Create root reducer from combineReducers and "loose" properties
- React Props is Not Defined
- Loading multiple react apps on the same page, override webpack output jsonpFunction in react-scripts
- Accessing ID of object in Array of objects,ReactJS
- Elegant way to inject custom hook into evolve function
- How do I modify the default name of react-redux connect function?
- React Context changes not showing
- POST API request in React js Form?
- React JS trying to map collection, value is not defined
- cannot create react element using es6
- FindIndex() removing items from redux store
- Typescript can't tell I'm returning early if param is undefined
- Issues with an object- Will not map
- Module not found: Error: Can't resolve 'date-fns/addDays' in 'C:\Users\
- How to create an formdata that contains a running index in its field name?
- Why is React treating my array as if it were empty?
- Input attribute doesn't update when const change value
- Webpack config for Code splitting not working for production build
- How to pass CSS from CSS module as prop in Next.js
- How To Get Google User Profile Info Using Access Token From OAuth?
- How do I update the value of text when I hold an button