@@ -101,22 +101,37 @@ func (p Props) Affirm() Props {
101101 return p
102102}
103103
104- // As retrieves the property with the given name from the Props
105- // and converts it to the specified type T.
106- func As [T any ](props Props , name string ) T {
107- if prop , ok := props [name ]; ok {
108- return prop .(T )
104+ func (p Props ) Get (key string ) any {
105+ if prop , ok := p [key ]; ok {
106+ return prop
109107 }
110108 panic (ErrUndefinedPropKey )
111109}
112110
113- // AsFunc retrieves the property with the given name from the Props
111+ func (p Props ) GetString (key string ) string {
112+ return p .Get (key ).(string )
113+ }
114+
115+ func (p Props ) GetBool (key string ) bool {
116+ return p .Get (key ).(bool )
117+ }
118+
119+ func (p Props ) GetFloat (key string ) float64 {
120+ return p .Get (key ).(float64 )
121+ }
122+
123+ func (p Props ) GetInt (key string ) int {
124+ return int (p .GetFloat (key ))
125+ }
126+
127+ // GetFunc retrieves the property with the given key from the Props
114128// and converts it to a function of type Func.
115- func AsFunc (props Props , name string ) Func {
116- if prop , ok := props [name ]; ok {
117- return Func (prop .(func (... any ) * js.Object ))
118- }
119- panic (ErrUndefinedPropKey )
129+ //
130+ // If a Setter is passed in as a prop, call this to read it out of the prop
131+ // as a Func since the externalizing of the Setter when passed through the
132+ // props will cause it to become a Func.
133+ func (p Props ) GetFunc (key string ) Func {
134+ return Func (p .Get (key ).(func (... any ) * js.Object ))
120135}
121136
122137// CreateElement creates a React element of the given type with the given props and children.
0 commit comments