Skip to content

Commit 302a65c

Browse files
committed
Add some more convenience methods to Props
1 parent 9f8c76e commit 302a65c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎this.go‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,30 @@ func (p Props) Interface(key string) interface{} {
167167
return nil
168168
}
169169

170+
// Int is convenience method to lookup a int value from props.
171+
func (p Props) Int(key string) int {
172+
if val, ok := p[key]; ok {
173+
return val.(*js.Object).Int()
174+
}
175+
return 0
176+
}
177+
178+
// Bool is convenience method to lookup a bool value from props.
179+
func (p Props) Bool(key string) bool {
180+
if val, ok := p[key]; ok {
181+
return val.(*js.Object).Bool()
182+
}
183+
panic(fmt.Sprintf("Props variable %q not found", key))
184+
}
185+
186+
// String is convenience method to lookup a bool value from props.
187+
func (p Props) String(key string) string {
188+
if val, ok := p[key]; ok {
189+
return val.(*js.Object).String()
190+
}
191+
return ""
192+
}
193+
170194
// Children represents a component's child component(s).
171195
// This is a fairly complex topic in Facebook's React, and more support may arrive here, eventually.
172196
// See https://facebook.github.io/react/tips/children-props-type.html

0 commit comments

Comments
 (0)