道具类型失败:提供给“按钮”的“对象”类型的道具“标签”无效,应为“字符串”

Failed prop type: Invalid prop `label` of type `object` supplied to `Button`, expected `string`

在我的 React 应用程序中,我收到了很多这样的警告:

大概returns来自这个:

<Button icon='save' type="submit" label={<T value="processes.new.save"/>} raised primary />

有办法解决这个问题吗?

谢谢

语言选择器:

之前我改变了它工作的翻译风格..

import React, {Component} from 'react';
import {createStore, combineReducers, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import {loadTranslations, setLocale, syncTranslationWithStore, i18nReducer} 
from 'react-redux-i18n';

import {de} from '../locales/de';
import {en} from '../locales/en';
export const translationsObject = {
    de: de,
    en: en
};

const store = createStore(
    combineReducers({
        i18n: i18nReducer
    }),
    applyMiddleware(thunk)
);
syncTranslationWithStore(store)
store.dispatch(loadTranslations(translationsObject));
store.dispatch(setLocale('de'));

function getLanguage() {
    const myState = store.getState();
    const local = myState.i18n.locale;
    return local;
}

class LanguageChooser extends Component {
    render() {
        return (
            <div>
                <li><a className="fa fa-language fa-2x" onClick={this.changeLanguage} aria-hidden="true"></a></li>
            </div>
        );
    }
    changeLanguage(e) {
        e.preventDefault();
        if (getLanguage() === "de") {
            store.dispatch(setLocale('en'));
        } else {
            store.dispatch(setLocale('de'));
        }
    }
}

export default LanguageChooser;

有什么问题?我没有收到错误

If for some reason, you cannot use the components, you can use the I18n.t and I18n.l helpers instead:

var I18n = require('react-redux-i18n').I18n;

I18n.t('application.title'); // => returns 'Toffe app met i18n!' for locale 'nl'

这是你的情况,"reason" 你不想使用组件是因为你需要将翻译后的文本作为 string 道具传递给 Button 组件。

所以,您可能需要这样的东西:

import {I18n} from 'react-redux-i18n';

然后

<Button icon='save' type="submit" label={ I18n.t('processes.new.save') } raised primary />

警告应该会消失。