ctrlplusb / react-async-bootstrapper

Execute a bootstrap method on your React/Preact components. Useful for data prefetching and other activities.
MIT License
117 stars 12 forks source link

asyncBootstrap is not called when using create-react-app #6

Closed burrack closed 6 years ago

burrack commented 7 years ago

Hi, I tried to follow the example in the docs and for some reason the asyncBootstrap function is not called inside Product. i'm using create-react-app. Did it happen to you maybe ?

bguiz commented 7 years ago

same happening here.

in src/index.js:

asyncBootstrapper(App).then(() => {
  reactSnapshotRender(<App />, document.getElementById('root'));
  registerServiceWorker();
});

in src/Page.js

class Page extends Component {
  asyncBootstrap() {
    console.log('Page.asyncBootstrap');
  }

The console.log statement never gets printed.

The hierarchy is: App -> Router -> div -> Switch -> Route -> Page

(using create-react-app with:

    "react": "^15.6.1",
    "react-async-bootstrapper": "^1.1.1",
    "react-router-dom": "^4.1.1",

)

SleepWalker commented 6 years ago

@bguiz here is your mistake:

reactSnapshotRender(, document.getElementById('root'));

You have bootstrapped some App and then rendered the completely fresh new <App /> instead.

it should be:

const App = <App />;

asyncBootstrapper(App).then(() => {
  reactSnapshotRender(App, document.getElementById('root'));
  registerServiceWorker();
});