Skip to content

Commit

Permalink
Document createTyped/ComponentTyped
Browse files Browse the repository at this point in the history
  • Loading branch information
AmberGraceRblx authored Nov 18, 2021
1 parent 5cb6b32 commit 1e1a54e
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions docs/api/elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ permalink: /api/elements

```lua
Pract.create(
classNameOrComponent: string | Pract.Component,
props: Pract.PropsArgument?,
children: Pract.ChildrenArgument?
classNameOrComponent: string | Pract.Component,
props: Pract.PropsArgument?,
children: Pract.ChildrenArgument?
): Pract.Element
```

Expand All @@ -28,6 +28,7 @@ The `children` argument is shorthand for `Pract.Children` and will override that

If the first argument to `Pract.create` is a [Component](../basic/components) (a function, typed `(Pract.PropsArgument) -> Pract.Element`), Pract will call this component when mounted or updating with the props provided as the component's first argument, and then mount or update the component's returned elements to the same host context.


## Pract.stamp

```lua
Expand Down Expand Up @@ -92,4 +93,33 @@ Pract.combine(

See: [State](../advanced/combine) for more detailed examples using `Pract.combine`

Returns an element which instructs pract to mount multiple elements with the same host context. A good use case for this is having components dedicated to user input mounted together with components, which decorate the same instance. With `Pract.combine`, user input components can be re-used, while visual components can be more specialized.
Returns an element which instructs pract to mount multiple elements with the same host context. A good use case for this is having components dedicated to user input mounted together with components, which decorate the same instance. With `Pract.combine`, user input components can be re-used, while visual components can be more specialized.

## Pract.createTyped


```lua
Pract.createTyped<PropsType>(
component: ComponentTyped<PropsType>,
props: PropsType
) -> (Types.Element)
```

Creates a create element representing a Component. Will respect the Props typing for that component, if defined via a `ComponentTyped<PropsType>` type annotation.
e.g.
```lua
export type Props = {
glowColor: Color3
}
local MyComponent: Pract.ComponentTyped<Props> = function(props)
return Pract.stamp(path.to.my.template, {
ImageColor3 = props.glowColor
}
end

-- . . .

local myElement = Pract.createTyped(MyComponent, { -- This props table is properly typechecked by luau!
glowColor = Color3.fromRGB(255, 0, 0),
})
```

0 comments on commit 1e1a54e

Please sign in to comment.