tora框架安装-react-mac

因为不能够使用antd mobilemobile,导致很多UI组件都需要重新封装开发,考虑了很久,最后还是在uni-app + vue与tora+react中选择了后者,哭了,为啥使用redux也要报错,还好taro的路由跳转够用。

react项目
1.安装react,创建模版项目

yarn global add create-react-app
//使用yarn而不是npm
//https://stackoverflow.com/questions/69648394/npm-warn-deprecated-tar2-2-2-this-version-of-tar-is-no-longer-supported-and-w/70329028

npx create-react-app cyt01
//npx解决mac上安装问题
//https://juejin.cn/post/7142666525365764104

2.运行react

yarn start

taro框架下react项目
1.安装taro,创建模版项目

yarn global add @tarojs/cli

 npx @tarojs/cli init myApp
//选择react,声明式描述UI和hooks
//选择sass,功能更强大
//选择webpack5,对lodash,压缩等都做了优化
//https://juejin.cn/post/6990869970385109005

2.编译运行

# yarn
$ yarn dev:weapp
$ yarn build:weapp

参考:https://taro-docs.jd.com/docs/GETTING-STARTED
基本上按照taro官方文档来做就行,在开发之前最好将taro中react相关的部分都看一遍,以免开发时遇到结构性的bug,却不知道来源。

3.添加redux

yarn add redux react-redux redux-thunk redux-logger

4.不使用react- route,而是在app.config.js中配置页面信息即可。

export default {
  pages: ['pages/index/index', 'pages/logs/logs'],
}

其他:
1.react-thunk

//以下摘抄自:https://zhuanlan.zhihu.com/p/85403048
其实thunk是函数编程届的一个专有名词,主要用于calculation delay,也就是延迟计算。
用代码演示如下:

function wrapper(arg) {
  // 内部返回的函数就叫`thunk`
  return function thunk() {
    console.log('thunk running, arg: ', arg)
  }
}
// 我们通过调用wrapper来获得thunk
const thunk = wrapper('wrapper arg')

// 然后在需要的地方再去执行thunk
thunk()
可以看到,这种代码的模式是非常简单的,以前我们可能都写过类似这样的代码,只是不知道这种代码叫做thunk而已。

2.应用中所有的 state 都以一个对象树的形式储存在一个单一的 store 中。 惟一改变 state 的办法是触发 action (描述如何处理state的对象)。 为了实现根据 action 的信息来改变 state 树,你需要编写 reducers。

3.Reducer 的任务是根据传入的 Action 对象去修改状态树。

或者简单地讲 Reducer 就是一个纯函数, 根据传入的 当前state 和 action ,返回一个新的 state :

(state, action) => newState

比如我们这个例子中的 Reducer 应该是这样的:

const initialState = {
    text : 'Hello world'
}

function Reducer(state=initialState, action) {
    switch(action.type) {
        case 'CHANGE_TEXT':
            return {
                text : 'Hello Stark'
            }
        default:
            return state;
    }
}

参考:https://www.zhihu.com/question/41312576?sort=created

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容