rmdort / react-redux-multilingual

A simple and slim multi-lingual component for React with Redux without react-intl or react-i18n
41 stars 14 forks source link

is it impossible to make static method for translate? #21

Closed kindslayer closed 4 years ago

kindslayer commented 4 years ago

for example, in my react component, I want to use a custom class to handle Http errors, And I can't pass the translate method to this class.

class ForgetPassword extends Component {
    handleSubmitForm = async event => {
        event.preventDefault();

        await Http.post('v1/reset-password', getToken())
            .catch(response => {
                new HttpErrors(response);
            })
    };

    render() { Lab lab lab . }
}

export default ForgetPassword;

and here is my class

import _ from "lodash";
import NativeToast from "components/Toast/NativeToast";

class HttpErrors {
    constructor({response}) {
        this.error = '';
        this.response = response;
    }

    handleError = () => {
        switch (this.response.status) {
            case 404:
                this.error = translate('errors.404');
                break;
        }

        this.makeNativeToast();
    };

    makeNativeToast() {
        NativeToast({message: this.error, type: 'error'});
    }
}

export default HttpErrors;
Wathis commented 4 years ago

PR already openned : https://github.com/rmdort/react-redux-multilingual/pull/20

rmdort commented 4 years ago

Thanks. Sorry. Will merge and publish in a few hours

rmdort commented 4 years ago

Done. Thank you