Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
kdong007 opened this issue Aug 4, 2022 · 0 comments

Comments

@kdong007
Copy link

kdong007 commented Aug 4, 2022

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

@kdong007 kdong007 changed the title how do you update state from a Android Fragment/View parent? like React's useimperativehandle how do you update state from a Android Fragment/View parent? like React's useImperativeHandle Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant