I'm using jQuery along with ReactJS for several things. I've noticed that the out put of $(selector)
is different when I do it within React vs directly in the browser console.
Due to this reason, certain javascript code that I execute directly in the browser console works, but it doesn't work when I write it within a React.
For example I have this table:
render(){
console.log(this.state.data);
return (
<Table striped bordered condensed hover id="files-table">
<thead>
<tr>
<th>stuff</th>
</tr>
</thead>
<tbody>
<tr>
<td>stuff</td>
</tr>
</tbody>
</Table>
);
}
On the one hand when I do console.log($('#files-table'))
inside React let's say in the componentDidUpdate()
hook, I see this output in the console:
... on the other hand the same console statement typed directly in the browser console shows this output (which is the one that I expect):
Can someone explain the differences?
I'm having a problem with implementing jQuery DataTables as putting $('#files-table').DataTable()
in React componentDidUpdate()
hook gives an error: $(...).DataTable is not a function Although it works in the browser (I know this error can be caused by loading jQuery twice, etc. but I don't think that's the case here).