In short, you’re trying to create an object and pass it the property of another object. That doesn’t make much sense, because it will be an object with an empty property, and you’re trying to multiply an object by a number and add to another object. You see how confusing it is?
The structure of creating an object is to place identifiers and properties of those identifiers between keys ({propriedade: props.max}
), and, if you try to multiply this object (instead of its parameters), you will generate errors.
In short, let’s say props.max = 45
. In that case, you’re doing the following:
{"45"}
And this cannot (or at least should not) be multiplied by anything else in this specific context (let us ignore for now all the kinds of operations we can do with strings, objects and concatenations). So you don’t need to create an object, you need to collect the value from within an existing object.
We corrected the code by removing the keys:
export default (props) => {
const Aleatorio = parseInt (Math.random () * props.max + props.min);
return (
<div>
<h2> O valor aleatório é {Aleatorio}</h2>
</div>
);
}
If you want to better understand the concept, I recommend reading a little about initialization of objects with Javascript.
Solution link in Stackblitz