Yes, I would say that there are drawbacks to using jQuery in React.
VDOM differential algorithm gets confused
You mentioned that. Yes, it will be good if you use only attributes read-only
, but if you do not target older browsers, then something like document.querySelector
will be lighter.
Any decentration you bring, especially in the form of a library, must be carefully checked. For more information see the Epidemic Obesity Site .
In addition, the idea of “I will use it read-only and let React do the rest” will add a significant level of confusion to your code, as we will see in the following example.
You refuse React templates
, . , :
React - , HTML, CSS JavaScript-, state
.
, UserProfile
. , push- :
// Please note this is simplified pseudo-code, and will likely not work
class UserProfile extends Component {
state = {
name: 'Bob',
profilePic: 'someurl.com/profile-pic',
isReceivingNotifications: false
}
updateReceivingNotifications = () => {
this.setState({ isReceivingNotifications: !this.state.isReceivingNotifications })
}
render() {
const { name, profilePic, isReceivingNotifcations } = this.state;
return (
<div>
<h2>{name}</h2>
<img src={profilePic} />
<input type="checkbox" checked={isReceivingNotifications} onChange={this.updateReceivingNotifications} />
</div>
);
}
}
, . isReceivingNotifcations
, .
:
class UserProfile extends Component {
state = {
name: 'Bob',
profilePic: 'someurl.com/profile-pic',
isReceivingNotifications: false
}
componentDidMount() {
const checkBox = document.getElementById('my-checkbox');
const that = this;
checkBox.addEventListener('change', function() {
if (this.checked) {
that.setState({ isReceivingNotifcations: true });
} else {
that.setState({ isReceivingNotifcations: false });
}
});
}
render() {
const { name, profilePic, isReceivingNotifcations } = this.state;
return (
<div>
<h2>{name}</h2>
<img src={profilePic} />
<input
type="checkbox"
checked={isReceivingNotifications}
id="my-checkbox"
/>
</div>
);
}
}
, , jQuery DOM-, .
, , - , .
, ?
React. React. jQuery , React , .
- jQuery, React
, . , -, React.