Platform
Solutions
Resources
Pricing
Sign in
Sign up
Sébastien Pierre
Using Observable for software engineering, programming language and user interface research.
Workspace
Fork
Public
Libraries
By
Sébastien Pierre
Edited
Aug 12, 2022
Importers
Insert cell
Insert cell
Insert cell
render
(
htm
`<svg width=100 height=100>
<circle cx=50 cy=50 r=50 fill=#673ab8 />
<text fill=white font-size=60 x=30 y=70 font-family="Helvetica,Arial">P.</text></svg>`
)
Insert cell
Insert cell
Insert cell
render
(
html
.
div
(
html
.
p
(
"To use preact:"
)
,
html
.
ul
(
html
.
li
(
"Use the "
,
html
.
code
(
"html"
)
,
" or "
,
html
.
code
(
"svg"
)
,
" functions to create virtual nodes"
)
,
html
.
li
(
"Use the "
,
html
.
code
(
"render"
)
,
" function to render your virtual nodes into a container, or the document itself by default"
)
)
)
)
Insert cell
render
(
svg
.
svg
(
{
width
:
300
,
height
:
300
,
viewBox
:
"0 0 600 600"
}
,
svg
.
circle
(
{
cx
:
200
,
cy
:
400
,
r
:
200
,
fill
:
"red"
,
opacity
:
0.5
}
)
,
svg
.
circle
(
{
cx
:
300
,
cy
:
200
,
r
:
200
,
fill
:
"green"
,
opacity
:
0.5
}
)
,
svg
.
circle
(
{
cx
:
400
,
cy
:
400
,
r
:
200
,
fill
:
"blue"
,
opacity
:
0.5
}
)
)
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Counter
=
(
props
,
dispatch
)
=>
{
const
{
count
}
=
props
return
html
.
div
(
"Counter: "
,
count
,
" "
,
html
.
button
(
{
onclick
:
_
=>
dispatch
(
"inc"
)
}
,
"+"
)
)
}
Insert cell
stateful
(
Counter
,
CounterController
,
state
=>
{
mutable
CounterState
=
state
}
)
(
CounterState
)
Insert cell
Insert cell
render
(
(
(
)
=>
{
const
[
count
,
setCount
]
=
useState
(
0
)
;
return
html
.
div
(
"Counter: "
,
count
,
" "
,
html
.
button
(
{
onclick
:
_
=>
setCount
(
count
+
1
)
}
,
"+"
)
)
}
)
(
)
,
"stateful"
)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
stateful
=
(
component
,
controller
,
updater
)
=>
{
var
rev
=
undefined
;
var
cached
=
undefined
;
var
root
=
document
.
createElement
(
"div"
)
const
renderer
=
(
state
)
=>
{
state
.
rev
=
state
.
rev
||
0
;
if
(
!
state
||
rev
!==
state
.
rev
)
{
cached
=
component
(
state
,
(
...
args
)
=>
updater
(
controller
(
state
,
...
args
)
||
state
)
)
}
render
(
cached
,
root
)
;
return
root
;
}
return
renderer
;
}
Insert cell
Insert cell
isAttributes
=
attr
=>
attr
instanceof
Object
&&
(
!
(
attr
instanceof
Array
)
)
&&
(
!
(
attr
.
props
)
)
Insert cell
Insert cell
Insert cell
PreactVersion
=
"10.10.2"
Insert cell
Insert cell
useState
=
preact
.
useState
Insert cell
Insert cell
htm
=
(
await
require
(
"htm@1/dist/htm.js"
)
)
.
bind
(
preact
.
createElement
)
Insert cell
Insert cell
One platform
to build and deploy the best data apps
Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
CounterState
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
CounterController
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Counter
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
html
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
svg
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
render
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
stateful
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
isAttributes
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
normaliseAttributes
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
PreactVersion
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
preact
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
useState
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
htm
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML