redux

How do I use types defined by @types/redux-form in React component with Field and FieldArray?

人盡茶涼 提交于 2020-05-13 17:48:09
问题 I'm developing app with React, Redux, Redux-Form and TypeScript. I am struggling to use types defined by package @types/redux-form (DefinitelyTyped), especially with FieldArray. There is an attribute "component" where I pass reference to component, but I have no clue what type should I use when describing its props. I downloaded example of using FieldArray from Redux-Form repository and slightly modified it to work with TypeScript. I want to compile it with compilerOption "noImplicitAny":

React Native (Redux) FlatList jumping to top of list when onEndReached called

﹥>﹥吖頭↗ 提交于 2020-05-13 06:03:23
问题 I have a FlatList in ReactNative which pulls a list of articles from an API. When the end of the list is reached on scrolling, a further page of articles is pulled from the API and appended to the articles list in a Redux reducer. The FlatList is set up as: render() { return( <FlatList data={this.props.articles.articles} // The initial articles list via Redux state renderItem={this.renderArticleListItem} // Just renders the list item. onEndReached={this.pageArticles.bind(this)} // Simply

React - How to check if JWT is valid before sending a post request?

前提是你 提交于 2020-05-12 11:37:10
问题 another noob question. I'm logging in my user to the system using JWT authorization, getting the token and saving it in localstorage and then sending a post request that saves data (its a big form basically). Problem is, the sever is invalidating the token after a given time (20 minutes or so) and so, some of my post requests are returning 401 status . How to verify (and if needed, show a login prompt) before sending the post request? I'm using redux-form to make my forms. P.S: I know I'm

How to solve data loading issue in React redux

我的未来我决定 提交于 2020-05-09 10:19:32
问题 I am trying to figure out how can i manage/display this component when data is still loading. I am using react redux for this case. any suggestion for solving this out? Although I wrapped this with lazy loading but it seems it is not that much working in this case. Any suggestion for this. //Actions.js export const getContact= () => dispatch => { dispatch(setResumesLoading()); axios .get('/api/contacts') .then(res => dispatch({ type: GET_CONTACTS, payload: res.data }) ).catch (err => dispatch

React/redux app renders blank screen on Safari

烈酒焚心 提交于 2020-05-09 02:24:11
问题 I built an app in React/redux that works in every browser I tried, BUT Safari on MacOS and any browser on iPhone. I get no error, no console message, nothing that would give me some idea. It only renders tag in Safari and the screen is blank. http://podcast.exploration.io Do you have any idea how could I trace this issue? Thanks 回答1: I found the issue. The main reason why it failed was 'fetch' function...which is not available in Safari. I'm not sure why it wouldn't print anything, but I

关于异步

筅森魡賤 提交于 2020-05-08 11:58:05
一、概述 js的执行环境是‘单线程’的,异步操作是至关重要的。异步任务就是任务需要分阶段完成,各阶段可以插入其他任务,否则就是同步任务。 二、实现 js处理异步任务主要分了3个阶段: 回调函数:异步任务拆分成多个阶段的代码,将这些代码用函数包裹以便在满足条件的时候继续异步任务,该函数被称为回调函数。这样处理主要缺点是:异步任务的逻辑被拆分了,异步任务嵌套异步任务后会形成‘回调地狱’,代码耦合程度太高。 Promise和Generator:Promise是回调函数的语法糖,主要解决‘回调地狱’的问题。Generator的特性类似‘协程’,目前的实现只能说是‘半协程’,只有Generator的实例有执行权。Generator通过yield来将异步任务分阶段,每一个阶段结束都会保留当前的执行上下文,调用next方法执行下一个阶段。缺点就是需要手动执行next,错误处理有些破坏结构。 async:async函数是Generator的语法糖,结合Promise将Generator自动化并返回Promise实例,通过await来分阶段,缺点是会阻塞,错误处理没有优化。 三、总结 现在Generator主要用来模仿线程操作(redux-saga)和生成Iterator对象,处理异步任务基本结合使用async和Promise。 来源: oschina 链接: https://my.oschina

react+redux项目框架搭建流程

帅比萌擦擦* 提交于 2020-05-08 06:10:06
一、脚手架搭建react结构目录: 1、npm install -g create-react-app 全局安装react脚手架 2、create-react-app react-demo 创建react-demo项目 3、cd react-demo 进入到项目文件夹 4、npm start 启动本地项目 二、Styled-Components与Reset.css的结合使用. Styled-Components解决css样式表不能私有的问题,且可以将组件与样式结合,方便构建小组件。Reset.css重置不同浏览器标签默认设置 三、React-Redux进行应用数据的管理 有些组件的数据,你认为是只有该组件要用,但是随着项目不断扩展,说不定其他组件也要用,这时候既然用了React-Redux管理数据,就是要将所有的数据都交给其管理 React-Redux和Redux这两个包都是结合使用的,React-Redux有个Provider核心组件,这点注意 四、combineReducers完成对数据的拆分管理 项目越大,reducer.js代码越多,所以构建项目时候就先要进行拆分处理 五、actionCreators与constants的拆分 action对象的创建,acitonType的常量都要单独写在一个文件中进行管理 六、使用Immutable.js来管理store中的数据

经验教程|常用设计模式整理

[亡魂溺海] 提交于 2020-05-07 18:20:27
#前言 为什么要学习设计模式?迫切想提升自己,却找不到方向,整体梳理了一下知识体系,觉得还是从基础开始。设计模式不是看一遍就学会的, 需要不断在编写、优化代码的过程中深入理解 。 设计模式的定义是: “在面向对象软件设计过程中针对特定问题的简洁而优雅的解决方案” 通俗一点说,设计模式是 在某种场合下对某个问题的一种解决方案 。如果再通俗一点说,设计模式就是 给面向对象软件开发中的一些好的设计取个名字 。 相信大家都听过三十六计,走为上策,意为败局已定,无可挽回,唯有退却,方是上策。在战场上,瞬息万变,统帅不可能和士兵慢慢的分析局势。一个跑字,简洁明了,能让士兵们直接领悟到统帅表达的意思。 适合JavaScript的设计原则,对其他设计原则感兴趣的同学可以自行百度。 1 单一职责原则 功能要单一 。一个对象(方法)只做一件事情。 2 最少知识原则 尽量 减少对象之间的交互 。如果两个对象之间不必彼此直接通信,那么这两个对象就不要发生直接的相互联系。 3 开闭原则 对扩展开放,对修改关闭。 当需要改变一个程序的功能或者给这个程序增加新功能的时候,可以使用增加代码的方式,但是不允许改动程序的源代码。 单例模式的定义是: 保证一个类仅有一个实例 ,并提供一个访问它的 全局访问点 。 有一些对象往往只需要一个,例如vuex和redux中的store、购物车、登录弹出等等。

React Hooks总结

心已入冬 提交于 2020-05-05 08:44:23
Hook 前言 什么是Hook 自从 16.8 版本开始,hooks 的出现使得你可以在不编写 class 的情况下使用状态管理以及其它 React 的特性。 那么在 React Hooks 出现之前,class 类组件和 function 函数组件有什么区别?Hooks 出现之后,函数组件又是如何满足原来只有类组件才有的功能的? 1.类组件和没有 hooks 加持的函数组件: 函数组件常被称为无状态组件,意思就是它内部没有状态管理,只能做一些展示型的组件或者是完全受控组件。因此差别主要体现在: 函数组件没有内部状态管理 函数组件内部没有生命周期钩子 函数组件不能被获取组件实例 ref,函数组件内也不能获取类组件的 ref 2.类组件和有 hooks 加持的函数组件: 有了 hooks 加持之后,函数组件具备了状态管理,除了可以使用内置的 hooks ,我们还可以自定义 hooks。 类组件有完备的生命周期钩子,而函数组件只能具备:DidMount / WillUnmount / DidUpdate / willUpdate 函数组件内部可以通过内置 hook 获取类组件 ref,也可以通过一些 API 的组合使用达到获取函数组件 ref 的功能 函数组件具备了针对状态变量的 setter 监听(类似于 vue watch),类组件没有这种 API。(useCallback

Django自带认证系统邮件模板自定义

萝らか妹 提交于 2020-05-02 10:22:02
这几天部署Docker设置Nginx遇到了邮件发送问题 首先我的问题就是,在服务器上部署Docker之后 然后宿主机的Nginx设置代理 server { listen 80; server_name cumt.studio www.cumt.studio; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8003; } } proxy_pass监听了Docker内网端口 然后代码使用了Django自带的认证系统 以及封装好的Django-registration-redux注册模块 使用上面的Nginx接收的邮件里只有example.com 然后找到了一个解决办法 需要设置proxy_host,将host代理为你的域名 好吧.....我太菜 不是很懂Nginx配置,搜了好久,搞了好久 也问了一些人,我放弃了........... (或许以后某一天就懂了....orzzz) 怎么办?? 然后想到flask中模板可以自定义