bbaldino
01/08/2021, 6:37 PMbbaldino
01/08/2021, 6:45 PMbbaldino
01/08/2021, 6:46 PMval someKey = props.key ?: defaultProps.key
and just use a kotlin-style default value.Marc Knaup
01/08/2021, 6:53 PMRBuilder
extension functions which in turn have default parameter values and create the props internally.
That’s one reason I’ve created https://github.com/fluidsonic/fluid-react as an alternative. Doesn’t support kotlin-styled though.bbaldino
01/08/2021, 6:54 PMMarc Knaup
01/08/2021, 6:55 PMdata class
not class
though.
Only external interface
for props.bbaldino
01/08/2021, 6:55 PMbbaldino
01/08/2021, 6:56 PMprops.someKey ?: defaultProps?.someKey
bbaldino
01/08/2021, 6:56 PMprops.someKey ?: defaultProps?.someKey
does seem to work as expectedMarc Knaup
01/08/2021, 6:56 PMRStatics
approachbbaldino
01/08/2021, 6:57 PMprops.someKey
was still undefined, but defaultProps.someKey
was set.Marc Knaup
01/08/2021, 6:57 PMbbaldino
01/08/2021, 6:57 PMbbaldino
01/08/2021, 6:57 PMMyClass : RComponent<...>
Marc Knaup
01/08/2021, 6:58 PMbbaldino
01/08/2021, 7:00 PMprops.someKey
is showing it. Maybe the local rebuild hadn't deployed yet.Marc Knaup
01/08/2021, 7:00 PMbbaldino
01/08/2021, 7:01 PMconsole.log(props.someKey ?: defaultProps?.someKey)
and then changed it back to just console.log(props.someKey)
and thought it worked...but it just hadn't updated yetbbaldino
01/08/2021, 7:02 PMprops.someKey
does not show the value, but defaultProps?.someKey
does.Marc Knaup
01/08/2021, 7:02 PMbbaldino
01/08/2021, 7:02 PMClass
for props.bbaldino
01/08/2021, 7:03 PMbbaldino
01/08/2021, 7:03 PMcompanion object : RStatics<GraphSelectionProps, RState, GraphSelection, Nothing>(GraphSelection::class) {
init {
defaultProps = GraphSelectionProps().apply {
allKeys = listOf("1", "2", "3")
}
}
}
bbaldino
01/08/2021, 7:03 PMexternal interface GraphSelectionProps : RProps {
var allKeys: List<String>
// An optional property which can contain stored data to be graphed
var data: List<dynamic>?
}
fun GraphSelectionProps(): GraphSelectionProps = js("{}").unsafeCast<GraphSelectionProps>()
Marc Knaup
01/08/2021, 7:04 PMbbaldino
01/08/2021, 7:06 PMdefaultProps
into props
? You don't have to check both?Marc Knaup
01/08/2021, 7:07 PMbbaldino
01/08/2021, 7:08 PMbbaldino
01/08/2021, 7:15 PMbbaldino
01/08/2021, 7:21 PMbbaldino
01/08/2021, 7:22 PMMarc Knaup
01/08/2021, 7:22 PMbbaldino
01/08/2021, 7:29 PMMarc Knaup
01/08/2021, 7:29 PMbbaldino
01/08/2021, 7:30 PMbbaldino
01/08/2021, 7:31 PMbbaldino
01/08/2021, 7:57 PMthisRef: RComponent<P, *>
, thisRef
has access to props
but doesn't have access to defaultProps
(even though inside my RComponent
subclass I do)--I dunno if there's something weird with the hierarchy there.Marc Knaup
01/08/2021, 8:01 PMdefaultProps
is set on the component class, props
only on the instance of the classMarc Knaup
01/08/2021, 8:01 PMbbaldino
01/08/2021, 8:01 PM