1

I want to import this react-infinite-scroller react library in a rails project but meet some problems. After I installed it, I could not import it using import InfiniteScroll from 'react-infinite-scroller'; or var InfiniteScroll = require('react-infinite-scroller')['default']; in application.js. There would be a SyntaxError: unterminated string literal for the first one and ReferenceError: require is not defined for the second one.

I also tried this library react-infinite and installed it using bower. I used like this

        <react-infinite containerHeight={200} elementHeight={40}>
      <ContentTable
        data={this.state.tableData}
        filterText={this.state.filterText}
        onUserClick={this.handleUserClick}
        dataType={this.props.dataType}
        showPublic={this.state.publicCheckbox}
      />
        </react-infinite> 

It was imported I guess because I could see the component in the html.enter image description here

But there was no infinite scrolling on the table.

I think react-infinite-scroller might save me because I saw Is it possible to add infinite scrolling to React Tool Box Table body?. But I could not import it right.

This project is 5 years old and I am new to react. Could someone save me? Thanks.

XINDI LI
  • 625
  • 2
  • 7
  • 16

1 Answers1

0

I would look into the Webpacker gem for Rails 5.

https://github.com/rails/webpacker

This allows you to write React.js components and include the packs (components/scripts) using javascript_pack_tag.

It also allows for ES6 syntax, which is what you are trying to do with your import statement. It allows for the require statement as well, as long as you install that library using npm.

JGrishey
  • 75
  • 5