React函数式组件与类组件通用写法

// 函数式组件

// 函数式组件
import React, { useEffect, useReducer, useState } from 'react';
import { observer } from 'mobx-react';
import { toJS } from 'mobx';
import { Input, Button, InputNumber, Modal } from 'antd';
import style from './style.less';

const initState = {
    companyKey: '',
};
const reducer = (state, action) => {
    return { ...state, ...action.params };
};

export default observer(props => {
    const [queryParams, dispatch] = useReducer(reducer, initState);
    const handleChange = (val, key) => {
        dispatch({ params: { [key]: val } });
    };
    const handleCancelAuthorization = () => { };
    const handleSaveAuthorization = async () => { };

    return (
        <Modal
            width={590}
            title={`${props.type === 'add' ? '添加授权' : '编辑授权'}`}
            visible={true}
            maskClosable={false}
            onOk={handleSaveAuthorization}
            onCancel={handleCancelAuthorization}
            footer={[
                <Button className={style.query_btn_bg} key="submit" type="primary" loading={loading} onClick={handleSaveAuthorization}>
                    保存
                </Button>,
                <Button className={style.cancel_btn} key="back" onClick={handleCancelAuthorization}>
                    取消
                </Button>
            ]}>
            <div className={style.modal_c}>
                <Input value={queryParams.companyKey} onChange={e => handleChange(e.target.value, 'companyKey')} />
            </div>
        </Modal>
    );
});



// 类组件

// 类组件
import React, {Component} from 'react';
import {observer} from 'mobx-react';
import {Table, Input, Button, InputNumber, Select, Popconfirm, Modal} from 'antd';
import noticeStore from '@stores/Notice';
import {toJS} from 'mobx';
import {filtergQparams} from '@lib';
import style from './style.less';

@observer
export default class Index extends Component {
    constructor(props) {
        super(props);
        this.state = {
        };
    }

    async componentDidMount() {}

    render() {

        return (
            <div className={style.page_box}>
                111111
            </div>
        );
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值