javascript - importing and exporting es6 classes -
i want create es6 class reads data file , returns content of file, created class called filereader has constructor filepath , has method called getfilecontent
import fs 'fs'; import path 'path'; export class filereader { constructor(filepath) { this.filepath = filepath; fs.readfile(filepath, (err, data) => { if (err) { console.log(err); } this.filecontent = data; }); } getfilecontent(separator, columns) { console.log(this.filecontent); } } i have react component called orderlist want use filereader inside componentdidmount method read content of file
import react 'react'; import {filereader} '../utils/filereader'; class orderslist extends react.component { constructor(props, context) { super(props, context); } componentdidmount() { filereader reader = new filereader(''); reader.getfilecontent(',' , []); } render() { } } export default orderslist; the problem i'm getting error unexpected token reader what's wrong approach ?
change line: filereader reader = new filereader(''); const reader = new filereader('');
Comments
Post a Comment