What Is The Correct Way To Pass Props To Navitem
My code works but give an error so I just wanted to inform how I can prevent an error from showing up. I'd like to learn how to write correct code. This is what my code looks like
Solution 1:
To pass non-standard attributes through React, you must follow the HTML 5 convention of using the "data-" prefix and no camelCase. The following is allowed:
<NavItemeventKey={2 } data-active-city={activeCity}href="/shanghai">{activeCity}</NavItem>
Solution 2:
In your NavItem component, you probably have something like:
render: function() {
return <a href={this.props.href} activeCity={this.props.activeCity}>{this.props.children}</a>;
}
In the latest versions of React, you can't pass props to DOM elements that aren't real attributes without a warning (https://facebook.github.io/react/docs/dom-elements.html#all-supported-html-attributes).
You could fix by doing the following:
render: function() {
return<ahref={this.props.href}>{this.props.children}</a>;
}
Post a Comment for "What Is The Correct Way To Pass Props To Navitem"