У меня есть клиент api, который отлично работает, получая информацию от Json на веб-сайте. Я хочу добавить несколько новых строк в этот пакет контента после извлечения из веб-сайта.Добавить данные в Json после извлечения в React Native
Я читал о функции .push, но не знаю, где положить новый формат ES6 и не может отличить любую информацию в Google.
Я использую:
react-native-cli: 2.0.1
react-native: 0.40.0
Это код:
const BASE_URL = 'https://example.com/data.json';
customData = [
{
autor: 'Mike',
category: 'category name',
}
]
function getJsonData() {
return fetch(BASE_URL)
.then(response => response.json())
.then(data => data.items.item)
.then(myData => myData.push(customData)) // <- Trying to add custom data
.then(news => news.map(item => {
return {
autor: item.author,
category: item.category,
}
})
)
//.then(news => news.push(customData)) // <- Also I tried here
}
export { getJsonData }