A
A
ayapergenov2017-08-25 07:40:02
JavaScript
ayapergenov, 2017-08-25 07:40:02

How to connect your js script to a React.js component?

There is an Accordion component in which you need to connect a self-written js script.
I find only instructions for connecting libraries via npm.

import React, { Component } from 'react';
import './Accordion.css';

class Accordion extends Component {
    render() {
        return (
                <aside className="accordion">
                    <h1>News</h1>
                    <div className="opened-for-codepen">

                    </div>
                </aside>
        );
    }
}

export default Accordion;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artyom, 2017-08-25
@artalar

Connect it in the same way as other files / components. In this case, the file should have an export, like this:

const MathMax = (a, b) => {
  return Math.max(a,b);
}
export default MathMax;

Depending on the webpack settings (if you are building it), you don't need to write ".js"

C
Coder321, 2017-08-25
@Coder321

If this is a regular js file, then there are many options, copy it and convert it into a module, connect it to index, configure webpack

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question