Download React Class as .html file

28 views Asked by At

Here is an extremely simplified version of my React component:

export class SomePage extends Component {

  download() {
    // this needs to be downloaded as an .html file

    // is this the right way to go about it:
    let html = document.getElementsByClassName("second-child-div").innerHTML;

    // what else should be done here?
  }

  render () {
    return (
      <>
        <div className="first-child-div">Stuff here</div>
        <div className="second-child-div" onClick={()=>this.download()}>
           <span className="some-other-styling-here">yada yada</span>
           More html elements, styling, and text here
        </div>
      </>
    )
  }

}

I want the user to be able to:

  1. download second-child-div and
  2. save it as an .html file with all of the styling intact (i.e. "some-other-styling-here", etc.)
0

There are 0 answers