Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"prettier": {},
"dependencies": {
"@streamlit/component-v2-lib": "^0.1.0",
"@streamlit/component-v2-lib": "^0.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentArgs } from "@streamlit/component-v2-lib";
import { FrontendRendererArgs } from "@streamlit/component-v2-lib";
import {
CSSProperties,
FC,
Expand All @@ -18,7 +18,7 @@ export type MyComponentDataShape = {
};

export type MyComponentProps = Pick<
ComponentArgs<MyComponentStateShape, MyComponentDataShape>,
FrontendRendererArgs<MyComponentStateShape, MyComponentDataShape>,
"setStateValue"
> &
MyComponentDataShape;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Component, ComponentArgs } from "@streamlit/component-v2-lib";
import {
FrontendRenderer,
FrontendRendererArgs,
} from "@streamlit/component-v2-lib";
import { StrictMode } from "react";
import { createRoot, Root } from "react-dom/client";

Expand All @@ -9,9 +12,10 @@ import MyComponent, {

// Handle the possibility of multiple instances of the component to keep track
// of the React roots for each component instance.
const reactRoots: WeakMap<ComponentArgs["parentElement"], Root> = new WeakMap();
const reactRoots: WeakMap<FrontendRendererArgs["parentElement"], Root> =
new WeakMap();

const MyComponentRoot: Component<
const MyComponentRoot: FrontendRenderer<
MyComponentStateShape,
MyComponentDataShape
> = (args) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"prettier": {},
"dependencies": {
"@streamlit/component-v2-lib": "^0.1.0"
"@streamlit/component-v2-lib": "^0.2.0"
},
"devDependencies": {
"cross-env": "^10.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, ComponentArgs } from "@streamlit/component-v2-lib";
import {
FrontendRenderer,
FrontendRendererArgs,
} from "@streamlit/component-v2-lib";

export type ComponentState = {
export type FrontendState = {
num_clicks: number;
};

Expand All @@ -10,9 +13,14 @@ export type ComponentData = {

// Handle the possibility of multiple instances of the component to keep track
// of any long-running state for each component instance.
const instances: WeakMap<ComponentArgs["parentElement"], { numClicks: number }> = new WeakMap();

const MyComponent: Component<ComponentState, ComponentData> = (args) => {
const instances: WeakMap<
FrontendRendererArgs["parentElement"],
{ numClicks: number }
> = new WeakMap();

const MyComponent: FrontendRenderer<FrontendState, ComponentData> = (
args
) => {
const { parentElement, data, setStateValue } = args;

const rootElement = parentElement.querySelector(".component-root");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"prettier": {},
"dependencies": {
"@streamlit/component-v2-lib": "^0.1.0"
"@streamlit/component-v2-lib": "^0.2.0"
},
"devDependencies": {
"cross-env": "^10.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, ComponentArgs } from "@streamlit/component-v2-lib";
import {
FrontendRenderer,
FrontendRendererArgs,
} from "@streamlit/component-v2-lib";

export type ComponentState = {
export type FrontendState = {
num_clicks: number;
};

Expand All @@ -10,9 +13,14 @@ export type ComponentData = {

// Handle the possibility of multiple instances of the component to keep track
// of any long-running state for each component instance.
const instances: WeakMap<ComponentArgs["parentElement"], { numClicks: number }> = new WeakMap();

const MyComponent: Component<ComponentState, ComponentData> = (args) => {
const instances: WeakMap<
FrontendRendererArgs["parentElement"],
{ numClicks: number }
> = new WeakMap();

const MyComponent: FrontendRenderer<FrontendState, ComponentData> = (
args
) => {
const { parentElement, data, setStateValue } = args;

const rootElement = parentElement.querySelector(".component-root");
Expand Down
2 changes: 1 addition & 1 deletion templates/v2/template/my_component/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
],
"prettier": {},
"dependencies": {
"@streamlit/component-v2-lib": "^0.1.0",
"@streamlit/component-v2-lib": "^0.2.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ComponentArgs } from "@streamlit/component-v2-lib";
import { FrontendRendererArgs } from "@streamlit/component-v2-lib";
import {
CSSProperties,
FC,
Expand All @@ -18,7 +18,7 @@ export type MyComponentDataShape = {
};

export type MyComponentProps = Pick<
ComponentArgs<MyComponentStateShape, MyComponentDataShape>,
FrontendRendererArgs<MyComponentStateShape, MyComponentDataShape>,
"setStateValue"
> &
MyComponentDataShape;
Expand Down
10 changes: 7 additions & 3 deletions templates/v2/template/my_component/frontend/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Component, ComponentArgs } from "@streamlit/component-v2-lib";
import {
FrontendRenderer,
FrontendRendererArgs,
} from "@streamlit/component-v2-lib";
import { StrictMode } from "react";
import { createRoot, Root } from "react-dom/client";

Expand All @@ -9,9 +12,10 @@ import MyComponent, {

// Handle the possibility of multiple instances of the component to keep track
// of the React roots for each component instance.
const reactRoots: WeakMap<ComponentArgs["parentElement"], Root> = new WeakMap();
const reactRoots: WeakMap<FrontendRendererArgs["parentElement"], Root> =
new WeakMap();

const MyComponentRoot: Component<
const MyComponentRoot: FrontendRenderer<
MyComponentStateShape,
MyComponentDataShape
> = (args) => {
Expand Down