Below is part of my react component. I have a props named daysUntil coming into this component which contains a number. In this example it is being pass the number 0 which results in the fontWeight function returning 700
render: function() {
return (
<Text style={this.style()}>
{this.props.day}
</Text>
)
},
style: function() {
return {
fontWeight: this.fontWeight()
}
},
fontWeight: function() {
var weight = 7 - this.props.daysUntil;
return weight * 100;
}
I get the following error:
JSON value '700' of type NSNumber cannot be converted to NSSTring.
I'm assuming this is because font-weight expects the value to be in string format. What's the proper fix for this?
Thank you in advance!
In your fontWeight() function
return weight * 100;
maybe becomes:
var val= weight * 100;
return val.toString();
I had a similar problem, where I was passing in an icon instead of a uri to an Image. The code was written to accept icon = 'path/to/icon'
:
<Image source={{ uri: icon }}>
but I was passing in icon = require('path/to/icon')
and I had to switch the jsx to
<Image source={icon}>
fontWeight requires a string value and not an integer.
Just make sure you return a string:
return (weight * 100).toString();
Make also sure that your "weight" variable is not equal to zero.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With