Component Lifecycle
Understand the process
Component Creation
function randomUser() {
const user = State({})
return div(
p(`Name: ${user.get().name}`),
p(`Age: ${user.get().age}`)
)
}function randomUser() {
const user = State({})
onLoad(async () => {
let raw = await fetch("https://randomuser.me/api/") //the api to get random names
let json = JSON.parse( await raw.text() )
user.set({
name: json.results[0].name.first, //the API was structured this way, it's not implementation
age: json.results[0].dob.age
})
})
return $(() => div(
p(`Name: ${user.get().name}`),
p(`Age: ${user.get().age}`)
), user)
}Component Update
Component Removal
Last updated