How to include local javascript on a Gatsby page?

后端 未结 7 556
深忆病人
深忆病人 2020-11-30 07:48

I\'m a total React newbie and I guess there is something fundamental I don\'t quite understand here. A default Gatsby page looks like this. Is there a way to use a local .js

7条回答
  •  执笔经年
    2020-11-30 08:38

    Gatsby uses html.js in the src folder. Not index.html like most react projects.

    Example html.js file:

    import React from "react"
    import PropTypes from "prop-types"
    
    export default class HTML extends React.Component {
      render() {
        return (
          
            
              
              
              
              {this.props.headComponents}
            
            
              {this.props.preBodyComponents}
              
    {this.props.postBodyComponents} ) } } HTML.propTypes = { htmlAttributes: PropTypes.object, headComponents: PropTypes.array, bodyAttributes: PropTypes.object, preBodyComponents: PropTypes.array, body: PropTypes.string, postBodyComponents: PropTypes.array, }

    For adding custom Javascript using dangerouslySetInnerHTML inside src/html.js:

    
    
                                     
                  
提交回复
热议问题