Я хочу перестроить данные, и я использую этот код, извлекаю данные, реагирую на собственные хуки и хочу, чтобы таможенный массив данных извлекал объект
const listStoryS = `
query{
listStorys(limit : 100 ){
items{
Story{
key
}
StroyType
status
id
profile{
id
name
image{
key
}
}
}
}
}
`
const Stories = (props) => {
const [isModelOpen, setModel] = useState(false);
const [currentUserIndex, setCurrentUserIndex] = useState(0);
const [currentScrollValue, setCurrentScrollValue] = useState(0);
const [AllStories , SetStories] = useState([]);
const modalScroll = useRef(null);
useEffect( async ()=> {
await API.graphql(graphqlOperation(listStoryS)).then(data => {
const storyS = data.data.listStorys.items
const storiesS = []
storyS.filter( element => {
if (element.Story !== undefined && element.Story.length !=
0){
storiesS.push({
id : element.profile.id ,
username : element.profile.name,
profile : s3Url + element.profile.image.key,
stories : [
{
id : element.id,
type : element.StroyType,
duration: 2,
url : s3Url + element.Story.key
}
]
})
}
})
_.reduceRight(storiesS, function(flattened, other) {
return flattened.concat(other);
}, []);
SetStories(storiesS)
console.log("this is data",storiesS)
})
},[])
, и я получаю в console.log этот результат, это нерезультат, который я хочу, мне нужна помощь в извлечении любых данных по структуре желания
this is data Array [
Object {
"id": "e937dca2-8f25-4022-a627-e10983af0047",
"profile": "https://s3.eu-west-1.amazonaws.com/snaports-healiot/public/fb05efcf-e797-447a-8aa9-38163e78df19.jpg",
"stories": Array [
Object {
"duration": 2,
"id": "d1a236a7-8798-4c37-9a77-91eee0310772",
"type": "image",
"url": "https://s3.eu-west-1.amazonaws.com/snaports-healiot/public/922B74F7-C45F-4C22-812C-D363C86E66D9.jpg",
},
],
"username": "Ahmed ",
},
Object {
"id": "e937dca2-8f25-4022-a627-e10983af0047",
"profile": "https://s3.eu-west-1.amazonaws.com/snaports-healiot/public/fb05efcf-e797-447a-8aa9-38163e78df19.jpg",
"stories": Array [
Object {
"duration": 2,
"id": "db0a003b-08b1-4a5e-bb26-63ecf8092774",
"type": "image",
"url": "https://s3.eu-west-1.amazonaws.com/snaports-healiot/public/48EC852B-E33B-4A40-BA3C-7E0322864BA8.jpg",
},
],
"username": "Ahmed ",
},
]
Но я хочу получить эту структуру, в результате можно получить любые данные и таможенные данные по этой структуре ниже
const stories = [
{
username: 'Amit',
title: 'Pune Dairies',
profile: 'https://avatars0.githubusercontent.com/u/16208872?s=460&v=4',
stories: [
{
id: 1,
url: 'https://images.unsplash.com/photo-1532579853048-ec5f8f15f88d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60',
type: 'image',
duration: 2,
isReadMore: true,
},
],
},
{
username: 'Trinadh',
profile: 'https://avatars2.githubusercontent.com/u/45196619?s=460&v=4',
title: 'My Gallery',
stories: [
{
id: 1,
url: 'https://images.unsplash.com/photo-1500099817043-86d46000d58f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60',
type: 'image',
duration: 2,
isReadMore: true,
},
{
id: 2,
url: 'https://images.unsplash.com/photo-1476292026003-1df8db2694b8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60',
type: 'image',
duration: 2,
isSeen: false,
isReadMore: true,
isPaused: true,
},
{
id: 3,
url: 'https://images.unsplash.com/photo-1498982261566-1c28c9cf4c02?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60',
type: 'image',
duration: 2,
isSeen: false,
isReadMore: true,
isPaused: true,
},
],
},
{
username: 'Steve Jobs',
profile: 'https://s3.amazonaws.com/media.eremedia.com/uploads/2012/05/15181015/stevejobs.jpg',
title: ' Beach Moves',
stories: [
{
id: 1,
url: 'https://images.unsplash.com/photo-1515578706925-0dc1a7bfc8cb?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
type: 'image',
duration: 2,
isReadMore: true,
},
{
id: 3,
url: 'https://images.unsplash.com/photo-1496287437689-3c24997cca99?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60',
type: 'image',
duration: 2,
isSeen: false,
isReadMore: true,
isPaused: true,
},
{
id: 4,
url: 'https://images.unsplash.com/photo-1514870262631-55de0332faf6?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60',
type: 'image',
duration: 2,
isSeen: false,
isReadMore: true,
isPaused: true,
},
],
},
]