Giter Club home page Giter Club logo

think's People

Contributors

codearvin avatar

Watchers

 avatar  avatar

think's Issues

react+redux项目的一些思考

帮佳浩做前端的时候,算是从头开始构建一个完整的项目了,从构建到完成基本功能的过程中,随着需求的增加,暴露了很多问题,大部分都是最开始设计不合理导致的

技术选型

react + react-router + redux + antd + moment

问题

  1. 在写组件的时候不知道应该采用纯函数的形式还是class的形式。往往最开始的时候感觉功能不需要使用到state或生命周期之类的,但最后发现还是要改成class的形式
  2. 开始打算使用prop-types对组件的props进行检查,开始几个组件检查了,后面就由于各种原因没有继续
  3. 出于封装组件的需要,我把一些数据只储存在了组件自己的state中,开始是这样想的:数据封装起来后有利于复用(现在想想并不是这样)。但后来有其他页面的功能需要用到这个组件内部的数据与函数(其他页面需要用到搜索部分的数据和重新搜索),反倒不利于复用了
  4. 数据有的存在state中,有的存在redux中,在写的时候并没有仔细思考数据放在哪里更合适,后面发现有些数据放在redux更好一些。比如搜索的数据,如果这些数据都放在redux中,在页面回退的时候页面仍然可以保持之前的状态
  5. react-router的v4版本没有路由的钩子了?新版本没有怎么看,现在是在每个页面开始都加了判断(只加了一部分。。。),对于用户权限(有些页面只能管理员能进)的判断之类的,还要查一查在这个版本如何处理
  6. antd的form表单的问题。选项A只有在A情况下渲染,初始渲染的时候由于某些原因A渲染了,数据获取后变为B情况,A没有渲染,但在最后校验的时候还会校验A从而出现问题。我猜想是A渲染的时候Form表单记住了A,但后面A不渲染了,Form表单中记住的A没有删除从而导致问题。后来对情况判断那里做了一些处理解决了这个问题
  7. 采用react+redux写的样本代码太多了,action、reducer等等。数据流长一些就要跨好多个文件(夹)或组件

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.