Skip to content

Combinator for adding incremented key attribute #129

@jmatsushita

Description

@jmatsushita

Hi there,

Thanks a lot for the great library. I'm quite new to purescript so please bear with me if this is trivial.

I've ran into problems with using preact as the react engine (I think related to the webpack aliasing combined with libraries that pull their own react instance), so I've switched to regular react and I'm getting a lot of warnings for missing unique key props.

I thought I'd try to write a combinator to automatically add an incremented key to children elements but I'm stuck. I'm just starting to understand the 'using do notation as a monoid' pattern, so I'm out of my depth with this.

I guess the api could be something like:

view :: State -> HTML Event
view count = withKeys $
  div do
    button #! onClick (const Increment) $ text "Increment"
    span $ text (show count)
    button #! onClick (const Decrement) $ text "Decrement"

And withKeys would automatically "traverse" the "tree" and add incrementing keys for each layer, i.e. "1" for the top div, and 1 2 and 3 for the first button, span and second button respectively.

Is that something that would be useful for others too maybe?

Cheers,

Jun

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions