我在自定义组件上有一个函数,该函数很明显是一个回调,用于从调用它的位置重新呈现(this.setState())组件。
我正在努力应对这些调用的正确语法。你能帮忙吗?
自定义组件
export class LanguageSelector extends Component {
afterChange(callback: any){
callback();
}
导入LanguageSelector的其他组件:
<LanguageSelector afterChange={() => { this.setState({}) }} ></LanguageSelector>
LanguageSelector
import React, { Component } from 'react';
import {
View,
} from 'react-native';
import { TouchableOpacity } from 'react-native';
import Flag from 'react-native-flags';
import { Global } from '../global'
import PropTypes from 'prop-types';
export class LanguageSelector extends Component {
afterChange(callback: any) {
callback();
}
changeLang(lang: string) {
Global.localizedStrings.setLanguage(lang);
//this.setState({});
}
render() {
return (
<View style={{ paddingBottom: 10, flexDirection: "row", alignSelf: "flex-end" }}>
<TouchableOpacity onPress={() => this.changeLang('de')}>
<Flag code="DE" size={32} />
</TouchableOpacity>
<TouchableOpacity onPress={() => this.changeLang('en-US')}>
<Flag code="GB" size={32} />
</TouchableOpacity>
</View>
)
}
}
答案 0 :(得分:3)
对不起,您认为您正在使用Typescript时,可以使用此选项,或者直接在所需的位置使用this.props.afterChange()。
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Providers\{5fd3d285-0dd9-4362-8855-e0abaacd4af6}]
@="WLA"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\Credential Provider Filters\{5fd3d285-0dd9-4362-8855-e0abaacd4af6}]
@="WLA"
[HKEY_CLASSES_ROOT\CLSID\{5fd3d285-0dd9-4362-8855-e0abaacd4af6}]
@="WLA"
[HKEY_CLASSES_ROOT\CLSID\{5fd3d285-0dd9-4362-8855-e0abaacd4af6}\InprocServer32]
@="C:\\WLA\\WLA.dll"
"ThreadingModel"="Apartment"
interface LanguageSelectorProps{
afterChange: () => void;
}