我怎样才能将jQuery代码放到jSX文件中

时间:2018-03-31 01:27:34

标签: javascript reactjs

const END_POINT = 'http://localhost:3000'
export default class Header extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            user: {
                id: '',
                first_name: '',
                last_name: '',
                gender: '',
                birthday: '',
                email: '',
                profile: ''
            },
            signInModalIsOpen: false,
            signUpModalIsOpen: false,
            notificationModalIsOpen: false,
            makeQuestionModalIsOpen: false,
            ForgotPasswordModalIsOpen: false
            // isAuthenticated: props.isAuthenticated
        }

        this.findAuthenticationToken = this.findAuthenticationToken.bind(this)
    }
    componentDidMount() {
        this.fetchUser()
    }

    findAuthenticationToken() {
        localStorage.getItem('sessionId') ?
            this.setState({ isAuthenticated: true }) :
            this.setState({ isAuthenticated: false })
    }

    openSignInModal() {
        this.setState({ signInModalIsOpen: true })
        const body = document.getElementsByTagName('body')[0]
        body.style.overflow = 'hidden'
    }

上面的代码由react.js编码,在这个时候,我想添加如下的jQuery代码。 如果我将jQuery代码添加到html文件中,我知道类型为<script></script>的类型,然后将代码放在<head></head>内 但是在这个时候,我不知道如何将jQuery代码放到jSX文件中。

$(function() {
    $('.navToggle').click(function() {
        $(this).toggleClass('active');

        if ($(this).hasClass('active')) {
            $('.globalMenuSp').addClass('active');
        } else {
            $('.globalMenuSp').removeClass('active');
        }
    });
});

0 个答案:

没有答案