I defined a css object inside of my render method but I am trying to figure out how to make text unselectable. React.js has their own key names like backgroundColor instead of background-color for css objects. I am trying to figure out key name for unselectable styles? Example:
render:function(){
var ListItems={
cursor:'pointer',
color:'black',
marginLeft:'-20px',
marginTop:'-10px',
marginBottom:'14px',
userSelect:'none',
}
if(this.state.linkHover=='hoverLink'){
ListItems.color='blue';
}else{
ListItems.color='black';
}
return (
<div>
<li style={ListItems} onMouseEnter={this.onMouseEnter} onMouseLeave={this.onMouseLeave} onClick={this.onClick}><input type="checkbox" checked={this.state.checked} unselectable="on"/>{this.props.value}</li>
</div>
)
}
userSelect doesn't seem to work in Chrome. Is there a different name?
You can use user-select: none; on the elements you don't want to be selectable by the user.
A key is a unique identifier. In React, it is used to identify which items have changed, updated, or deleted from the Lists. It is useful when we dynamically created components or when the users alter the lists.
Yes, that is true, key is a restricted keyword and doesn't get propagated as props. Keys serve as a hint to React but they don't get passed to your components. If you need the same value in your component, pass it explicitly as a prop with a different name: const content = posts.
Key is kind of the id for the element, and it helps React to identify which element was changed, added, or removed. It's a good practice to select a value that is a unique identifier for an item in the array, commonly it's the ID. Let's modify our example.
user-select has the following css names:
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
According to this, react's names are:
MozUserSelect: "none"
WebkitUserSelect: "none"
msUserSelect: "none"
Every hyphen -
and the following character is replaced by according uppercase letter.
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