Reputation: 343
I've got a question, because i can't find answer anywhere. The problem is: what is the initial value of the following hook: "Function" Example:
function Example() {
const [settings, setSettings] = useState({});
return (
...
);
}
And here i'm writing this function "Example" as class, but i don't know how to initialize state (is it empty string or empty list or 0 value?)
class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
settings: <-- and what here?
};
}
Upvotes: 0
Views: 32
Reputation: 6664
useState
is passed the initial value as its only param - in your case {}
.
You can accomplish the same in your second code snippet like so:
class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
settings: {}
};
}
}
Upvotes: 1