I'm currently trying to do conditional statements which allow me to display the divs according to the User's role. First I call for the role and set it to the state value.
The sets are fine as I can view in the dev tools console. However when I try to do the following conditional check on a constant which is a string:
props = {
subRole = ''
}
{(!this.state.AdminRole && subRole.toString() === READ_ONLY (
//div goes here
))}
Then I get:
Object(...) is not a function
on the subRole.toString() === READ_ONLY
check and Webstorm is telling:
method expression is not of function type
I'm currently trying to do conditional statements which allow me to display the divs according to the User's role. First I call for the role and set it to the state value.
The sets are fine as I can view in the dev tools console. However when I try to do the following conditional check on a constant which is a string:
props = {
subRole = ''
}
{(!this.state.AdminRole && subRole.toString() === READ_ONLY (
//div goes here
))}
Then I get:
Object(...) is not a function
on the subRole.toString() === READ_ONLY
check and Webstorm is telling:
method expression is not of function type
Share
Improve this question
edited Aug 26, 2018 at 9:14
Timisorean
1,5167 gold badges22 silver badges31 bronze badges
asked Aug 26, 2018 at 8:59
RollingStonesRollingStones
331 gold badge1 silver badge4 bronze badges
0
2 Answers
Reset to default 1You have declared subRole incorrectly. In object notation we use :
for keys.
Please do the following changes first:
props = {
subRole : ''
}
If you want to initialize default props:
// for example your ponent is App.js
App.defaultProps = {
roles : {
subRole: 'c'
}
};
Later you can access this in your ponent like:
this.props.roles.subRole
This is the remended way but usually we don't use default props, instead we are more concerned with the ponent's default state.
READ_ONLY is being called as a method which is why you get the error. Add &&
before rendering element:
{(!this.state.AdminRole && subRole.toString() === READ_ONLY && (
//div goes here
))}
Also, Fix =
props = {
subRole : ''
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745235948a4617892.html
评论列表(0条)