-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
For a reason that I do not know, my store is undefined on "first render".
In that capture of devtools console, I log a property of my store.
It is first undefined
then HMR comes and then the property is defined
.
import { Component } from 'preact';
import { connect } from 'unistore/preact';
@connect(['toast'])
class Toast extends Component {
render ({toast}, {}) {
console.log(toast);
return (
<div class="toast-container">
<div class="toast">
{/*toast.messages.map((message, index) => (
<p class="toast--content" key={index}>{message}</p>
))*/}
</div>
</div>
)
}
}
export default Toast;
// store/worker.js
import createStore from 'stockroom/worker';
import idbKeyVal from 'idb-keyval';
import Constants from '../constants';
const store = createStore({
user: {
userId: '',
email: '',
avatar: ''
},
toast: {
messages: [],
show: false
}
});
// globally available actions
store.registerActions(store => ({
toasting ({toast}, messages) {
return {
toast: {
messages,
show: true
}
};
}
}));
// index.js
import createStore from 'stockroom';
import storeWorker from 'workerize-loader!./store/worker';
import { Provider, connect } from 'unistore/preact';
import devtools from 'unistore/devtools';
const production = process.env.NODE_ENV === 'production';
const store = production ? createStore(storeWorker()) : devtools(createStore(storeWorker()));
import './style/index.scss';
import App from './components/app';
export default () => (
<Provider store={store}>
<App />
</Provider>
);
I don't have that problem when I only use unistore without stockroom.
btzr-io
Metadata
Metadata
Assignees
Labels
No labels