Comments (10)
Hi @echarles, fortunately, I just managed to make it work. Thank you for suggesting the meeting; your support is greatly appreciated.
from jupyter-ui.
This has been discussed in #79 and resulted with a example you can link from https://jupyter-ui.datalayer.tech/docs/state/redux/
from jupyter-ui.
@BrandonEscamilla Maybe you have already seen that example, please tell me if it help or not, so I can look a bit more to the code you shared.
from jupyter-ui.
Hey @echarles, thank you for you answer, in fact, I did check out the resource you shared. But I'm a bit confused about whether I need to set up the store like we usually do in Redux, or is simply creating the store with const store = createReduxEpicStore(); enough? Also, I'm not sure if I have to worry about this part: injectableStore.inject('init', exampleReducer);. Any insights you could give me on this?
Appreciate your help!
from jupyter-ui.
const store = createReduxEpicStore(); enough? Also, I'm not sure if I have to worry about this part:
It should be enough
injectableStore.inject('init', exampleReducer);. Any insights you could give me on this?
The easiest is to start from the ExampleState file and change it to fit your needs. There may be other constructs to integrate Redux, but that example is the easiest I have found. You could copy/paste it and change it to your needs.
from jupyter-ui.
Hi @echarles, I'm currently encountering some challenges while trying to implement this. Could you please suggest any alternative resources or references that I can explore? Thank you in advance!
from jupyter-ui.
Just sent an invite to connect on linkedin and schedule a call. Is your repo public so I can already have a look?
from jupyter-ui.
That is awesome news ❤️ At some point, this community will benefit from your knowledge if this can be published in the open.
Anyway I let you share here what is possible, and let you close it after. Thx again.
from jupyter-ui.
Hey @echarles, thanks for the support. I managed to solve the issue by creating the store using the createReduxEpicStore()
function provided by jupyter-ui, before I was creating the store using redux-toolkit but it was not working. In Next.js, I simply created the store using that function and passed it to the Redux provider. To access the store in the page where I'm using Jupyter notebooks, I used the useStore()
selector. The example reducer is just a copy-paste of the one in the repo as well. Here's the code:
//layout.tsx
import { Provider } from "react-redux";
import { createReduxEpicStore } from "@datalayer/jupyter-react";
const store = createReduxEpicStore()
<Provider store={store}>
{children}
</Provider>
//page.tsx
import { exampleReducer } from '@/redux/ExampleState';
import { Jupyter, notebookActions, createInjectableStore } from '@datalayer/jupyter-react';
const store = useStore()
const injectableStore = createInjectableStore(store);
injectableStore.inject('init', exampleReducer);
<Jupyter
injectableStore={injectableStore}
.....
>
// ExampleState.ts
import { useSelector } from "react-redux";
import actionCreatorFactory from "typescript-fsa";
import { reducerWithInitialState } from "typescript-fsa-reducers";
import { IJupyterReactState } from "@datalayer/jupyter-react";
/* State */
export interface IExampleState {
foo?: Date;
}
export const initExampleState: IExampleState = {
foo: undefined,
}
/* Selectors */
export const selectFoo = (): Date | undefined =>
useSelector((state: IJupyterReactState) => {
if (state.init) {
return (state.init as IExampleState).foo;
}
return initExampleState.foo;
}
);
/* Actions */
export enum ExampleActionType {
UPDATE_FOO = "jupyterReact/UPDATE_FOO",
}
const actionCreator = actionCreatorFactory('jupyterReact');
export const exampleActions = {
updateFoo: actionCreator<Date>(
ExampleActionType.UPDATE_FOO
),
}
/* Reducers */
export const exampleReducer = reducerWithInitialState(initExampleState)
.case(exampleActions.updateFoo, (state: IExampleState, foo: Date) => {
return {
...state,
foo,
};
}
);
from jupyter-ui.
Super! Thx for sharing. Closing as resolved.
from jupyter-ui.
Related Issues (20)
- Add NotebookLite and CellLite and fix ConsoleLite to Storybook
- Storybook Pyodide is failing via CDN while succeeding via S3 Bucket HOT 3
- Firefox does not resize the Storybook view for the Cell
- Support Xeus Python Lite kernels and Emscripten Forge environments with `lite` option HOT 2
- Add a initCode props to the components
- Upgrade to JupyterLab 4.1.0b0 HOT 1
- Global CSS cannot be imported from node_modules HOT 3
- Restore IPyWidgets state if available HOT 1
- Package and export the Webpack configuration
- Upgrading to `@jupyterlite/server(-extension)` 0.2.3 breaks jupyter ui lite
- Jupyter Hub support HOT 6
- Preinstalling Libraries when using a notebook component rather than JupyterLabs component HOT 1
- Right click on the JupyterLabApp component makes the layout to shift up and open bottom panel HOT 4
- Bug on saving a file HOT 1
- Creating Custom Toolbar | Sidebar HOT 2
- Issue with Vite Example HOT 6
- Markdown collapsing instead of rendering. HOT 1
- Cell height is off by as much as 30+x HOT 3
- Typescript Version Issue HOT 1
- Issue with nextjsExample HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jupyter-ui.