Quiz
Explore your understanding of how to create strongly-typed props, state, and access modifiers in React class components with TypeScript. This quiz helps reinforce key concepts before moving on to typing component events and handlers.
We'll cover the following...
We'll cover the following...
Creating strongly-typed class components
1.
We have a CountDown component that has no props but has a count state. How can we declare the CountDown component with strongly-typed count state and initialize it to 10?
A.
type State = {
count: number;
};
class CountDown extends React.Component<State> {
constructor(props: {}) {
super(props);
this.state = {
count: 10
};
}
...
}
B.
type State = {
count: number;
};
class CountDown extends React.Component<{}, State> {
constructor() {
this.state = {
count: 10
};
}
...
}
C.
class CountDown extends React.Component<{}, {count: number}> {
constructor(props: {}) {
super(props);
this.state = {
count: 10
};
}
...
}
1 / 5
In the next ...