<Route path="/news" component={News} exact />
<Route path="/news/:id" component={NewsPost} />
News
componentDidMount() {
fetch("./db/db.json")
.then(response => response.json())
.then(data => {
this.newsList = data.news;
this.setState({ news: data.news.slice(0, 10) });
});
window.addEventListener("scroll", () => {
const root = document.documentElement || document.body;
if (
root.scrollTop + window.innerHeight === root.offsetHeight &&
this.state.news.length < this.newsList.length
)
this.state.news.push(
this.newsList.slice(
this.state.news.length,
this.state.news.length + 3
)[0]
);
});
}
NewsPost
componentDidMount() {
fetch("./db/db.json")
.then(response => response.json())
.then(data => {
console.log(data);
this.newsList = data.news;
this.newsPost = data.news.filter(e => e.id === 1)[0];
this.setState({
news: data.news.filter(e => e.id !== 1).slice(0, 10)
});
});
window.addEventListener("scroll", () => {
const root = document.documentElement || document.body;
if (
root.scrollTop + window.innerHeight === root.offsetHeight &&
this.state.news.length + 1 < this.newsList.length
)
this.state.news.push(
this.newsList.slice(
this.state.news.length,
this.state.news.length + 3
)[0]
);
});
}
На странице News нет проблем все загружается а на NewsPost в консоле ошибка
Uncaught (in promise) SyntaxError: Unexpected token < in JSON at position 0