Reputation: 9545
How do i set the type of this state in my component
state: any = {
profile: {
details: any: {
name: any: '',
email: any: '',
age: any: '',
cellNumber: any: '',
}
}
}
class NewNoteForm extends Component<props> {
static defaultProps = {profileStore:{}}
state = {
profile: {
details: {
name: '',
email: '',
age: '',
cellNumber: '',
}
}
}
}
interface IDetails
{
name: string;
email: string;
age: number;
cellNumber: number;
}
interface IProfile
{
details: IDetails;
}
Upvotes: 0
Views: 98
Reputation: 112777
You can define an interface for the state and use it when you define the class.
Example
interface NewNoteFormProps {}
interface NewNoteFormState {
profile: {
details: {
name: string,
email: string,
age: string,
cellNumber: string
}
};
}
class NewNoteForm extends Component<NewNoteFormProps, NewNoteFormState> {
state = {
profile: {
details: {
name: "",
email: "",
age: "",
cellNumber: ""
}
}
};
render() {
// ...
}
}
Upvotes: 2