Answer the question
In order to leave comments, you need to log in
Import React Variables?
Evening at home! There was a problem, I have a component, I used js in it, but for convenience I changed some functions in javascript a little (I made such a mini library for myself), here is an example:
var $ = (selector) => {
return document.querySelector(selector)
}
Line 7: '$' is not defined no-undef
. React just doesn't see the $ variable even though I imported everything into the component, here's the code:import React, { Component } from 'react';
import './style.css';
import './param';
class Nav_btn extends Component {
componentDidMount = () => {
$('#nav-trigger').onclick = () => {
$('#menu-navigation').classList.add('active');
$('#menu-close').classList.add('active');
}
}
render() {
return (
<div>
<button id = 'nav-trigger'><div>Menu</div></button>
</div>
);
}
}
export default Nav_btn;
var $ = (selector) => {
return document.querySelector(selector)
}
Answer the question
In order to leave comments, you need to log in
export default function (selector) {
return document.querySelector(selector)
}
.......
import $ from './param'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question