我刚刚开始使用Redux持久化,由于某些原因,我无法让它工作。(无法读取未定义错误的属性“订阅”)
Persistor.js
import { createStore } from 'redux'
import { persistStore, persistReducer } from 'redux-persist'
import store from 'redux-persist/es/storage/session' // defaults to
localStorage for web and AsyncStorage for react
我已经学习了无数关于redux持久化的教程,并且相信在我的redux工具包应用程序中实现它是正确的。然而,我认为在我的基本理解上存在着一种脱节。我可以在使用REST的应用程序上使用持久化,还是需要设置后端服务器才能正常工作?如果您不能为一个使用REST的应用程序使用persist,我将如何在使用的应用程序上获得持久化状态?在“我的浏览器的devtools中的应用程序”中,它显示了我的状态已被保存,但是当我关闭浏览器窗口并重新打开它时,我发现购物车是空的。这是我的代码,以防我遗漏了什么:
Store js
import cartReducer from "./features/Cart/
我试图添加redux-持久化到我的反应项目(使用类型记录)。但我有麻烦了。编译时会出现以下错误:
Could not find a declaration file for module 'redux-persist/lib/storage'. '.../WebstormProjects/catalog/node_modules/redux-persist/lib/storage/index.js' implicitly has an 'any' type.
Try `npm install @types/redux-persist` if
最近我注意到,在useSelector中调用react-redux有点延迟。现在,我使用useEffect来检查状态是否是某个值。就像这样:
const user= useSelector(state=>state.user.value);
useEffect(()=>{
if (!user){
alert('You have to login to see this page');
//Redirect the visitor to the login page
}
},[]);
我注意到,useEffect在useSelec
我正在使用redux-工具箱,并且希望通过不必在每个分派异步操作之后调用unwrapResult来减少代码重复。我通过向用户显示一条土司消息来处理所有分派操作的错误,因此我需要根据redux工具包展开包装。
理想情况下,我希望使用如下所示的钩子包装从useDispatch()函数返回的returned中的分派函数.
// Example of wrapped dispatch function
function SomeComponent() {
const dispatch = useWrappedAppDispatch()
return (
<button
//我的商店
import {applyMiddleware, createStore} from "redux";
import thunk from "redux-thunk";
import rootReducer from "./reducer/index";
import AsyncStorage from "@react-native-async-storage/async-storage";
import {persistReducer,persistStore} from "redux-persist
我有一个简单的上传图像功能,在那里用户可以选择什么图像要上传的个人资料图片。image函数允许任何类型的图像。一旦用户上传了图像文件,它将保存在公共文件夹中由我指定的目录中,其中的名称将更改为如下所示。
if the userId = 32
then the image will be stored as 32.ext
其中"ext“是图像的扩展名。
我的问题是,当用户完成上传并转到个人资料页面时,何时检索图像。我只能使用一种文件类型,比如jpg,不能使用png或任何扩展名。
<img src="<?php echo "/public/images/even