Skip to content

Commit 641d24e

Browse files
chore: TCDICORE-146 fix double loader
1 parent 92d1073 commit 641d24e

2 files changed

Lines changed: 42 additions & 36 deletions

File tree

wp-react-lib/src/providers/PageProvider.jsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react'
1+
import React, { useEffect, useRef } from 'react'
22
import { Container, Loader, Segment } from "semantic-ui-react"
33
import { useDispatch, useSelector } from 'react-redux'
44
import { PageContext } from './Context'
@@ -30,8 +30,11 @@ const PageProvider = (props) => {
3030
const pages = useSelector(state => state.getIn(['wordpress', store, 'items']));
3131
const loading = useSelector(state => state.getIn(['wordpress', store, 'loading']));
3232

33+
const prevProps = useRef({parent, slug, locale, previewId, search}).current;
34+
3335
useEffect(() => {
34-
if (prevProps.parent !== parent || prevProps.slug !== slug || locale !== prevProps.locale || previewId !== prevProps.previewId | search != prevProps.search) {
36+
37+
if (prevProps.parent !== parent || prevProps.slug !== slug || locale !== prevProps.locale || previewId !== prevProps.previewId || search !== prevProps.search) {
3538
dispatch(getPages({
3639
before,
3740
perPage,
@@ -53,22 +56,22 @@ const PageProvider = (props) => {
5356
}
5457
}, [parent, slug, locale, previewId, search]);
5558

56-
// useEffect(() => {
57-
// dispatch(getPages({
58-
// before,
59-
// perPage,
60-
// page,
61-
// fields,
62-
// parent,
63-
// slug,
64-
// store,
65-
// locale,
66-
// previewNonce,
67-
// previewId,
68-
// search,
69-
// noCache
70-
// }));
71-
// }, []);
59+
useEffect(() => {
60+
dispatch(getPages({
61+
before,
62+
perPage,
63+
page,
64+
fields,
65+
parent,
66+
slug,
67+
store,
68+
locale,
69+
previewNonce,
70+
previewId,
71+
search,
72+
noCache
73+
}));
74+
}, []);
7275

7376
// Keep showing previous content while loading new content
7477
if (loading && !pages) {

wp-react-lib/src/providers/PostProvider.jsx

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react'
1+
import React, { useEffect, useRef } from 'react'
22
import { useDispatch, useSelector } from 'react-redux'
33
import { getPosts } from '../reducers/actions'
44
import { PostContext } from './Context'
@@ -30,7 +30,10 @@ const PostProvider = (props) => {
3030
const error = useSelector(state => state.getIn(['wordpress', store, 'error']));
3131
const loading = useSelector(state => state.getIn(['wordpress', store, 'loading']));
3232

33+
const prevProps = useRef({categories, locale, slug, taxonomy, page, perPage, search}).current;
34+
3335
useEffect(() => {
36+
3437
if (categories != prevProps.categories || locale != prevProps.locale || slug != prevProps.slug ||
3538
taxonomy != prevProps.taxonomy || page != prevProps.page || perPage != prevProps.perPage || search != prevProps.search
3639
) {
@@ -53,23 +56,23 @@ const PostProvider = (props) => {
5356

5457
}, [categories, locale, slug, taxonomy, page, perPage, search]);
5558

56-
// useEffect(() => {
57-
// dispatch(getPosts({
58-
// slug,
59-
// type,
60-
// taxonomy,
61-
// categories,
62-
// before,
63-
// perPage,
64-
// page,
65-
// fields,
66-
// store,
67-
// locale,
68-
// previewNonce,
69-
// previewId,
70-
// search
71-
// }));
72-
// }, []);
59+
useEffect(() => {
60+
dispatch(getPosts({
61+
slug,
62+
type,
63+
taxonomy,
64+
categories,
65+
before,
66+
perPage,
67+
page,
68+
fields,
69+
store,
70+
locale,
71+
previewNonce,
72+
previewId,
73+
search
74+
}));
75+
}, []);
7376

7477
if (posts && posts.length > 0) {
7578
return <PostContext.Provider value={{ posts, locale, meta }}>{children}</PostContext.Provider>;

0 commit comments

Comments
 (0)