Props
Props can be used to store custom data on your client
, and consume it wherever your client
is accessed. With optional type safety. They’re stored on the client.props
object and can be read/modified at any time, including when you create your client.
Type Safety
When we read our props TypeScript hasn’t got a clue what props you’ve added, and everything you read will be typed as any
. This isn’t great as we loose all benefits of typing when we use props.
To fix this we provide an ambient Props
interface declaration that you can add properties to. The default template comes with this setup like this:
- package.json
Directorysrc/
- index.js
- app.d.ts
You’ll now get intellisense and type checking for the props that you’ve told TypeScript about. You’ll still be able to access props that don’t exist, they’ll just continue to be typed as any.
Component Shortcut
All of the built-in components which have a run
handler also provide the props directly in the context as a shortcut, rather than needing to do client.props
. For example: