在Redux存储中存储URL对象好吗?

huangapple go评论55阅读模式
英文:

Is it good to store URL object in redux store?

问题

I tried to store the URL object in the react store and it is giving me error that:

在状态中检测到了一个不可序列化的值,在路径中:

Here is the URL reference in my store.
Code Reference:
在Redux存储中存储URL对象好吗?

Console error:
在Redux存储中存储URL对象好吗?

Is there an alternative way to store URL or how can we fix this error?

英文:

I tried to store the URL object in the react store and it is giving me error that:

A non-serializable value was detected in the state, in the path:

Here is the URL reference in my store.
Code Reference:
在Redux存储中存储URL对象好吗?

Console error:
在Redux存储中存储URL对象好吗?

Is there an alternative way to store URL or how can we fix this error?

答案1

得分: 1

只返回翻译好的部分:

"正如错误中所指出的,您应该只将可序列化的数据存储在Redux存储中。

只获取href属性如下:

const yourUrl = new URL(...);
console.log(yourUrl.href); 

有关更多文档,请访问MDN网站 https://developer.mozilla.org/en-US/docs/Web/API/URL"

英文:

As you have in the error, you should store only serializable data in the Redux store.

Get only the href propery like that:

const yourUrl = new URL(...);
console.log(yourUrl.href); 

More documentation here on the MDN Website https://developer.mozilla.org/en-US/docs/Web/API/URL

huangapple
  • 本文由 发表于 2023年4月17日 18:26:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034160.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定