redux

I am getting an error GET http://localhost:3000/api/products 404 (Not Found)

谁说我不能喝 提交于 2020-12-15 05:31:31
问题 Well, there are lots of questions in StackOverflow about this error I've seen all of them none of them is working for me. I'm using react with redux trying to fetch some products. my backend server node is running on port 5000 and I'm using concurrently to start both servers at the same time whenever I'm trying fetch the data its using port 3000 where is my frontend running. Please somebody help me to solve this issue package.json file { "name": "proshop", "version": "1.0.0", "description":

How to store and retrieve objects in react-redux? [Objects subscribed to local-storage]

梦想与她 提交于 2020-12-15 05:20:53
问题 I have a reducer like this: const UserReducer = (state=JSON.parse(localStorage.getItem('user')), action) => { switch(action.type){ default: return state; case "REFRESH_AUTH": return state = JSON.parse(JSON.stringify(action.payload.user)); case "CLEAR_AUTH": return state = null; } } I need to store an object here, and hence I need to stringify it before saving it. Now, though, when I reload the page and the reducer tries to get JSON.parse(localStorage.getItem('user')) I get this error:

How to store and retrieve objects in react-redux? [Objects subscribed to local-storage]

偶尔善良 提交于 2020-12-15 05:20:48
问题 I have a reducer like this: const UserReducer = (state=JSON.parse(localStorage.getItem('user')), action) => { switch(action.type){ default: return state; case "REFRESH_AUTH": return state = JSON.parse(JSON.stringify(action.payload.user)); case "CLEAR_AUTH": return state = null; } } I need to store an object here, and hence I need to stringify it before saving it. Now, though, when I reload the page and the reducer tries to get JSON.parse(localStorage.getItem('user')) I get this error:

Why is useReducer's dispatch causing re-renders?

夙愿已清 提交于 2020-12-13 12:12:00
问题 Suppose I implement a simple global loading state like this: // hooks/useLoading.js import React, { createContext, useContext, useReducer } from 'react'; const Context = createContext(); const { Provider } = Context; const initialState = { isLoading: false, }; function reducer(state, action) { switch (action.type) { case 'SET_LOADING_ON': { return { ...state, isLoading: true, }; } case 'SET_LOADING_OFF': { return { ...state, isLoading: false, }; } } } export const actionCreators = {

Why is useReducer's dispatch causing re-renders?

旧城冷巷雨未停 提交于 2020-12-13 12:10:35
问题 Suppose I implement a simple global loading state like this: // hooks/useLoading.js import React, { createContext, useContext, useReducer } from 'react'; const Context = createContext(); const { Provider } = Context; const initialState = { isLoading: false, }; function reducer(state, action) { switch (action.type) { case 'SET_LOADING_ON': { return { ...state, isLoading: true, }; } case 'SET_LOADING_OFF': { return { ...state, isLoading: false, }; } } } export const actionCreators = {

Why is useReducer's dispatch causing re-renders?

孤街浪徒 提交于 2020-12-13 12:09:27
问题 Suppose I implement a simple global loading state like this: // hooks/useLoading.js import React, { createContext, useContext, useReducer } from 'react'; const Context = createContext(); const { Provider } = Context; const initialState = { isLoading: false, }; function reducer(state, action) { switch (action.type) { case 'SET_LOADING_ON': { return { ...state, isLoading: true, }; } case 'SET_LOADING_OFF': { return { ...state, isLoading: false, }; } } } export const actionCreators = {

Draft.js - createWithContent or convertFromRaw throwing error

孤者浪人 提交于 2020-12-13 07:40:29
问题 i am trying to use Draft.js in the Blog app i am creating. It all seems fine when saving data to the database and getting it back, just i cannot seem to get createWithContent to work. I am going to show you most of my code for clarity, apologise if it may seem too much. This is how i set-up the project: this is the post model const postSchema = new mongoose.Schema( { title: { type: String, required: true, }, image: { type: String, required: true }, images: [String], paragraph: { type: String,

Draft.js - createWithContent or convertFromRaw throwing error

寵の児 提交于 2020-12-13 07:39:48
问题 i am trying to use Draft.js in the Blog app i am creating. It all seems fine when saving data to the database and getting it back, just i cannot seem to get createWithContent to work. I am going to show you most of my code for clarity, apologise if it may seem too much. This is how i set-up the project: this is the post model const postSchema = new mongoose.Schema( { title: { type: String, required: true, }, image: { type: String, required: true }, images: [String], paragraph: { type: String,

我遇到的前端面试题总结(2018)

可紊 提交于 2020-12-13 00:34:07
来到新公司上班已经快一个月的时间,趁着空闲时间把自己这段时间的面试题进行一波总结,避免再次踩坑,有些问题还是需要自己去查一下,有时间的话会把答案补全 关于模块化的理解,AMD、CMD规范 AMD、CMD规范其实就是require.js、sea.js在推广过程中对模块规范化的产出 模块化就是将一个大文件拆分成相互依赖的小文件,再进行统一的拼装和加载。只有这样,才有多人协作的可能 响应式布局的原理 响应式布局就是根据不同的屏幕大小设置不同的样式 Media Queries(媒体查询) 是响应式设计的核心 Redux的原则 单一数据源 数据是只读的 state的更改只能由纯函数修改 怎么通过路由对不同账号进行权限管理 这个其实就是账号权限的问题,一般后台系统会用这个,路由鉴权的问题,一般需要后台同学配合 重绘和回流 重绘:只改变dom样式会触发重绘 如 color 回流:改变dom的布局 如padding 回流肯定会触发重绘,重绘不一定会触发回流 词法作用域,为什么叫词法作用域 词法作用域又叫静态作用域,是在词法解析阶段已经确定了一个变量的作用域 promise 和 async关系 async是Generator的语法糖,返回一个promise对象 ajax拦截全局请求 ajax与fetch的关系与区别 ajax的实质是 XMLHttpRequest react生命周期 实例化:

支撑京东小程序的开发框架 「Taro」

坚强是说给别人听的谎言 提交于 2020-12-12 12:50:43
Taro 简介 现在支持小程序的平台太多了,例如: 微信小程序 QQ小程序 支付宝小程序 百度小程序 字节跳动小程序 针对他们都各自开发一套的话开发成本就太高了。 如果写一套代码,就能开发出适配这么多平台的小程序,是不是开发效率提升了好几倍。 Taro 的使命就是解决这个问题,多端支持,除了支持上面的那些小程序,还支持 H5、APP,一套代码,多处运行。 Taro 是京东的凹凸实验室推出的小程序框架,已经支撑了京东的多个核心业务,例如京东购物、京东到家。 Taro 在 GitHub 上收到 2.3w+ star,也很活跃,最近更新时间是 3 天前。 Taro 遵循的是 React 语法规范,只需要写一套代码,通过 Taro 编译工具,就可以编译出不同端的代码。 因为是基于 React,所以支持 React-Native,这样就可以轻松编译出 APP。 Taro 核心特性 支持使用 npm/yarn 安装管理第三方依赖。 支持使用 ES7/ES8 甚至更加新的 ES 规范,一切都可自行配置。 支持使用 CSS 预编译器,例如 Sass 等。 支持使用 Redux 进行状态管理。 支持使用 Mobx 进行状态管理。 小程序 API 优化,异步 API Promise 化等等。 学习资源 1. 免费 https://github.com/NervJS/awesome-taro