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

React Hooks v16.8 #121

Merged
merged 3 commits into from
Jul 22, 2019
Merged

React Hooks v16.8 #121

merged 3 commits into from
Jul 22, 2019

Conversation

Skolotsky
Copy link
Contributor

Wrappers for react hooks and way to create functional component like this

val renderCount = functionalComponent<RProps> {
    val (count, setCount) = useState(0)
    useEffect {
        console.log("useEffect $count")
    }
    +"count $count"
    button {
        attrs {
            onClickFunction = {
                setCount(count + 1)
            }
        }
    }
}

fun RBuilder.renderCount() {
    child(renderCount)
}

@JsName("useReducer")
external fun <S, A> rawUseReducer(reducer: RReducer<S, A>, initialState: S): RDependenciesArray
@JsName("useReducer")
external fun <S, A> rawUseReducer(reducer: RReducer<S, A>, initialState: S, initialAction: A): RDependenciesArray
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use initialAction: A = definedExternally and avoid duplicating the function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't sure that it's equal in converted js. And this "optimisation" is unnecessary.

@Leonya Leonya changed the title React Hooks v16.6 React Hooks v16.8 Jul 22, 2019
@Hypnosphi
Copy link
Contributor

Hypnosphi commented Sep 14, 2019

Hooks should only be defined inside a functional component body, so it's better to define them as extension functions on RBuilder or even define

@DslMarker
annotation class Hooks

@Hooks
open class RFunctionalBuilder: RBuilder() {
   fun useState(...)
   ...
}

/**
* Get functional component from [func]
*/
fun <P : RProps> functionalComponent(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

4 participants