Skip to content

how do you update state from a Android Fragment/View parent? like React's useImperativeHandle #908

Open
@kdong007

Description

Version

Add the version of the litho packages you use. You can paste the dependency
section of the gradle file if you have one.

litho 0.39.0
kotlin 1.3.72

Issues and Steps to Reproduce

Replace this with steps to repro your issue.

Assume I have component with state

class MyComponent() : KComponent() {

    override fun DslScope.render(): Component{
        val counter = useState { 0 }
        return Text(
            text = "Hello, World! $counter",
            textSize = Sp(50f),
        )
    }
}

Then i used it in some fragment/view

    val lithoView = LithoView.create(context /* context */, MyComponent())
    mBinding.lithoContainer.addView(lithoView)

Then how do I update state/prop of MyComponent from parent?
Which is equivalent to React's useimperativehandle
https://reactjs.org/docs/hooks-reference.html#useimperativehandle
https://dev.to/collegewap/how-to-call-the-child-component-function-from-the-parent-component-in-react-3559

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions