前端--React--一点微小的记录

在学习React中的一点微小的工作总结

以umi搭建的,融入qiankun,antd等的微前端。 使用我(菜逼)自己容易理解,通俗易懂的方式表达;文章会不断更新变得像我一样长,要是文中有纰漏请告诉我

1.生命周期

网上可以查到很多生命周期,我只记录实际项目中用得最多的

  • componentDidMount
    组件完全挂载到页面上才会被调用执行(render中的内容就是页面,把其他地方写的js文件引入到其中,就是挂载),所以可以保证数据的加载。此外在这个方法中调用setState可以触发重新渲染。放在这个生命周期里面的就是要在最开始展示页面时要有的数据,就会放在这里处理。
	  componentDidMount() {
   
	        const {
    unreadReminds } = this.props;
	        this.getListDatas(unreadReminds);//页面在初始化时需要需要getListDatas方法获取的数据
	    }


  • componentWillReceiveProps(nextProps)
    父组件的属性发生改变会影响到子组件(通过props传递父组件给子组件),nextProps就是最新的传递过来的状态,下面代码可以看到typeKeyunreadReminds就是从nextProps中取出来的,然后通过本组件方法 getListDatas()处理
      componentWillReceiveProps(`nextProps`) {
         
        const {
          typeKey, unreadReminds = {
         } } = nextProps;
        if (typeKey === 'Remind') this.getListDatas(unreadReminds);
    }
    

2.一些属性

state,props,constructor,setState,connect,ref

  • state
    它就是本组件的一个存放状态的仓库,在本组件中很多地方要用到的,甚至需要传递给本组件的子组件时。下图中在this.state中就是本组件自己创建的属性,注意到上面const { unreadReminds = {}, typeKey = '' } = props;就是从父组件中拿出这几个属性。
    constructor(props) {
   
        super();
        const {
    unreadReminds = {
   }, typeKey = '' } = props;
        this.state = {
   
            records: typeKey === 'Remind' ? unreadReminds.data : [],
            pagination: {
   
                paging: 1,
                current: 1,
                pageSize: 5,
                sort: '',
                total: -1,
            },
        };
    }

要是想要在底下方法中要使用this.state中的属性,使用const {属性}=this.state的方式拿出来

  disabledStartDate = startValue => {
   
    const {
    endValue } = this.state;
    if (!startValue || !endValue) {
   
      return false;
    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据引用,在安装@ant-design/react-native时,不再需要手动链接(@ant-design/icons-react-native),而是可以使用自动链接功能。只需要使用命令`npm install @ant-design/icons-react-native --save-dev`来安装@ant-design/icons-react-native即可。此外,可以在`node_modules/@ant-design`文件夹下找到安装的文件。 根据引用,可以使用命令`react-native -v`来检查是否成功安装了react-native。 根据引用,示例代码展示了如何全局使用ant-design-mobile组件。官方文档中的示例是按需引入的,如果要全局使用,需要手动引入相应的组件文件。示例代码中引入了Button和InputItem组件,并在App组件中使用了这些组件。 所以,ant-design-mobile是一个基于React Native的UI组件库,可以通过自动链接或手动引入组件文件的方式来使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [react native 0.70版本使用ant-design-mobile-rn及icons字体图标库](https://blog.csdn.net/weixin_43233914/article/details/126849915)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* [react native 使用ant-design-mobile-rn的icon字体库](https://blog.csdn.net/weixin_43233914/article/details/119450451)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值