3

I'm featching large amount on data and meanwhile I want to lazy load the react table

import React, {Component, Fragment, lazy, Suspense} from 'react'; 
const ReactTable = lazy(() => import("react-table")); 
render() 
{ 
return ( 
<Suspense fallback={<div>Loading...</div>}> 
{this.state.securityCheck.length ? 
<ReactTable columns={columns} data={this.state.securityCheck} /> 
: 
<div className='text-center' style= {{fontSize: '20px'}}>No data =
Available! </div> } 
</Suspense> 
) 
}
1
  • 1
    There are quite a few resources for this sort of thing online, I will leave one here: hackernoon.com/… In the mean time, please update your question with any specific issues you are getting as well as your current approach. Commented Jun 10, 2019 at 8:49

1 Answer 1

2

From the Docs:

The fallback prop accepts any React elements that you want to render while waiting for the component to load. You can place the Suspense component anywhere above the lazy component. You can even wrap multiple lazy components with a single Suspense component.

Try this,

<Suspense fallback={<div>Loading...</div>}> 
   <ReactTable columns={columns} data={this.state.securityCheck} /> 
</Suspense>
Sign up to request clarification or add additional context in comments.

2 Comments

const ReactTable = lazy(() => import("react-table")); Is this the right way to import React table for lazy load?
@ParthShrivastava Yes. It is the right way. Just make sure you are importing from correct path. For same folder we use ./filename, for other folder we use ../foldername/filename.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.