当我没有声明类别时,我无法加载帖子,但是如果我尝试设置默认类别,那么我不能为另一个类别更改类别?有没有想出主意怎么办?使用选择器 - Redux。
const catchTaxonomies = useSelector(
state => ({
catchTaxonomies: state.catchTaxonomies
})
);
let taxonomiesEqual = catchTaxonomies.catchTaxonomies;
根据来自 siedbar 的 catchTaxonomies 发送的类别从 Kentico 下载数据
const fetchArticles = categories => {
client.items()
.type("article")
.containsFilter("elements.categories", [categories])
.elementsParameter(["title", "image", "urlslug", "headline", "content", "pagination", "categories"])
.getObservable()
.subscribe(response => {
console.log(response.items);
if(response.pagination.nextPage) {
setLoadNewArticles(!loadNewArticles);
}else {
setLoadNewArticles(false);
}
setData(response.items);
setLoading(!isLoading);
});
}
我把这个函数放到 useEffect
useEffect(() => {
fetchArticles(taxonomiesEqual);
}, [])
错误信息:
filters.js:171 Uncaught TypeError: m.trim is not a function at filters.js:171 at Array.map () at ContainsFilter.getParamValue (filters.js:170) at url.helper.js:22 at Array.forEach () 在 UrlHelper.addOptionsToUrl (url.helper.js:20) 在 QueryService.BaseDeliveryQueryService.getUrl (base-delivery-> > query.service.js:93) 在 MultipleItemQuery.BaseQuery.resolveUrlInternal (base-query.class.js :57) 在 MultipleItemQuery.BaseItemQuery.getMultipleItemsQueryUrl (base-item-query.class.js:93) 在 MultipleItemQuery.BaseItemQuery.runMultipleItemsQuery (base-item-query.class.js:104) 在 MultipleItemQuery.getObservable (multiple-item- query.class.js:234) 在 fetchArticles (Main.js:33) 在 Main.js:53 在 commitHookEffectList (react-dom.development.js:18053) 在 commitPassiveHookEffects (react-dom.development.js:18080) 在 HTMLUnknownElement.callCallback (react-dom.development.js:147) 在 Object.invokeGuardedCallbackDev (react-dom.development.js:196) 在 invokeGuardedCallback (react-dom.development.js:250) 在 commitPassiveEffects (react- dom.development.js:19706) 在包装 (scheduler-tracing.development.js:177) 在 flushPassiveEffects (react-dom.development.js:19759) 在 renderRoot (react-dom.development.js:20332) 在 performWorkOnRoot ( react-dom.development.js:21357) 在 performWork (react-dom.development.js:21267) 在 performSyncWork (react-dom.development.js:21241) 在 requestWork (react-dom.development.js:21096) 在scheduleWork (react-dom.development.js:20909) 在 scheduleRootUpdate (react-dom.development.js:21604) 在 updateContainerAtExpirationTime (react-dom.development.js:21630) 在 updateContainer (react-dom.development.js:21698) 在 ReactRoot.push../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render (react-dom.development.js:22011) 在 react-dom.development。 js:22163 at unbatchedUpdates (react-dom.development.js:21486) at legacyRenderSubtreeIntoContainer (react-dom.development.js:22159) at Object.render (react-dom.development.js:22234) at Module../src /index.js (index.js:8) 在webpack_require (bootstrap:781) at fn (bootstrap:149) at Object.0 (index.js:10) at webpack_require (bootstrap:781) at checkDeferredModules (bootstrap:45) at Array.webpackJsonpCallback [as push] (bootstrap:32 ) 在 main.chunk.js:1