Skip to content

CCV2 Template Tutorials#1434

Open
sfc-gh-dmatthews wants to merge 6 commits intoprettier-python-difffrom
ccv2-template-tutorials
Open

CCV2 Template Tutorials#1434
sfc-gh-dmatthews wants to merge 6 commits intoprettier-python-difffrom
ccv2-template-tutorials

Conversation

@sfc-gh-dmatthews
Copy link
Contributor

@sfc-gh-dmatthews sfc-gh-dmatthews commented Mar 7, 2026

📚 Context

Added comprehensive tutorials for building custom components using the official component template. These tutorials provide step-by-step guidance for developers who want to create package-based custom components with either Pure TypeScript or React + TypeScript.

🧠 Description of Changes

Current:

The documentation had conceptual information about custom components but lacked practical, hands-on tutorials showing developers how to use the official component template.

Revised:

  • Added new tutorial section "Build custom components" with two comprehensive tutorials
  • Created tutorial for Pure TypeScript components covering project generation, code walkthrough, and extending the template with reset functionality
  • Created tutorial for React + TypeScript components covering React integration, component lifecycle management, and building interactive lists
  • Added cross-references from the package-based components concept page to the new tutorials
  • Included complete code examples, diff-based modifications, and production build instructions

Files added/modified:

  • content/develop/tutorials/custom-components/_index.md - New tutorial section landing page
  • content/develop/tutorials/custom-components/template-typescript.md - Pure TypeScript tutorial
  • content/develop/tutorials/custom-components/template-react.md - React + TypeScript tutorial
  • content/develop/tutorials/_index.md - Added custom components card
  • content/develop/concepts/custom-components/components-v2/package-based.md - Added tip box linking to tutorials
  • content/menu.md - Added navigation entries for new tutorial pages

💥 Impact

Size:

  • Not small

🌐 References

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

Copy link
Contributor Author

sfc-gh-dmatthews commented Mar 7, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@sfc-gh-dmatthews sfc-gh-dmatthews marked this pull request as ready for review March 7, 2026 16:30
@sfc-gh-dmatthews sfc-gh-dmatthews requested a review from a team as a code owner March 7, 2026 16:30
@sfc-gh-dmatthews sfc-gh-dmatthews force-pushed the ccv2-template-tutorials branch from c549445 to 01ddaf1 Compare March 8, 2026 20:06
@sfc-gh-dmatthews sfc-gh-dmatthews force-pushed the ccv2-template-tutorials branch from 01ddaf1 to 3b284ff Compare March 9, 2026 05:41
@sfc-gh-dmatthews sfc-gh-dmatthews requested review from sfc-gh-bnisco and removed request for a team March 9, 2026 22:25
└── vite-env.d.ts
```

Notice the React template has two frontend source files instead of one: `index.tsx` handles integration with Streamlit's lifecycle, and `MyComponent.tsx` contains the React component.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Putting these in separate files is a convention rather than a hard requirement. If someone wanted to put this all in 1 file, that would be fine! If they wanted to split it out into 100 files, that is also okay 😄 . Not sure any change to the wording here is necessary unless you think it would be clearer to make this distinction.

```

This file bridges Streamlit's component lifecycle and React. Because Streamlit calls your `FrontendRenderer` function on every re-render (whenever `data` changes), the pattern is different from a typical React app:
- **React root management**: You can't create a new React root each time Streamlit calls your function. Instead, the `WeakMap` stores one root per component instance, keyed by `parentElement`. On the first call, it creates the root. On subsequent calls, it re-renders into the existing root.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: One other implication is that this is how users implement support for multiple different instances of the same component running on the frontend at once. So if there is a one-time global setup (eg: loading some data from a 3rd party) that is needed, it only needs to be handled once at the global level, and can then be shared by all other instances.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants