haxe-react / react-native

React Native externs for Haxe
61 stars 9 forks source link

Custom componenet property binding #12

Closed varadig closed 7 years ago

varadig commented 7 years ago

I have another question. When I create custom componenet, how can I create property for that. So I need to inject value of custom componenet property, like text,source...etc

kevinresol commented 7 years ago
class MyComp extends react.ReactComponent.ReactComponentOfProps<{text:String, source:{uri:String}}> {}
varadig commented 7 years ago

So something like this?


package view.componenets;
import react.ReactComponent;
import haxe.macro.Expr;
import react.ReactMacro;
import react.ReactMacro.jsx;
import react.native.component.*;

class ImageBox extends ReactComponentOfProps<{text:String, source:{uri:String}}>{
    public function new() {

        super();
    }

    override function render() {
        return jsx("
        <View>
        <Text>{text}</Text>
        <Image source={source}></Image>
        </View>");
    }
}

I got this error when compile:


src/view/componenets/ImageBox.hx:16: lines 16-20 : Unknown identifier : text
src/view/componenets/ImageBox.hx:16: lines 16-20 : For function argument 'children'
kevinresol commented 7 years ago

You need to say props.text and props.source, just as in normal react.

varadig commented 7 years ago

Thanks you (y)