상태 관리를 위해 Redux를 사용하는 반응 기반 애플리케이션에서 무한 스크롤을 구현하려고합니다. 페이지 스크롤에 작업을 전달하려고합니다. 그러나 같은 것을 성취 할 수는 없습니다. 내 코드는 여기redux를 사용하는 무한 스크롤
// The Reducer Function
const pinterestReducer = function (state=[], action) {
if (action.type === 'SET_CONTENT') {
state = action.payload;
}
return state;
}
const appReducer = combineReducers({
pinterest: pinterestReducer
})
// Create a store by passing in the pinterestReducer
var store = createStore(appReducer);
window.onscroll = function(ev) {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
// you're at the bottom of the page, show all data
store.dispatch({
type: 'SET_CONTENT',
payload: travelJSON
});
}
};
travelJSON은 객체의 배열입니다. 처음에는 travelJSON의 처음 12 개 객체를 상태로 지정하는 액션을 전달합니다. 사용자가 스크롤은 페이지 하단에 나는 전체 JSON을 할당해야하는 경우 다음이 상태의 내 구성 요소를 만들고 사용은 다음과 같습니다
// Dispatch our first action to change the state
store.dispatch({
type: 'SET_CONTENT',
payload: travelJSON.slice(0,12)
});
render(
<Provider store={store}><Pinterest /></Provider>,
document.getElementById('page-container'));
더 많은 데이터를로드하는 코드가 표시되지 않았습니다. 'travelJSON'이란 무엇입니까? –
이 질문을 업데이트했습니다. 한번 봐주세요. –