fewkz / froact

Wrapper around Roact & Roact Hooks to simplify UI development and add full, correct Luau typing
MIT License
3 stars 0 forks source link

Add simple way to connect to property changed events #1

Closed fewkz closed 2 years ago

fewkz commented 2 years ago

Rather than having to do:

local height, setHeight = hooks.useState(0)
froact.TextLabel({
    Size = UDim2.new(1, 0, 0, height),
    Text = "Text",
    onChanged = function(rbx, property)
        if property == "TextBounds" then
            setHeight(rbx.TextBounds.Y)
        end
    end,
})

There should be a "bind" field that does the same:

local height, setHeight = hooks.useState(0)
froact.TextLabel({
    Size = UDim2.new(1, 0, 0, height),
    Text = "Text",
    bindTextBounds = setHeight,
})

In the background, this will create a callback for the Changed event. Bind fields will only be generated for properties prefixed with Absolute, or TextBounds