Skip to content

Natural index numbers on callback function#64

Description

@hallaji

Hi there 馃憢

I have a situation where I'd like to replace the matched regex with my own array of nodes respectively. It would be great receiving natural index numbers 0, 1, 2 on callback instead of odd ones.

const nodes: React.ReactNodeArray

// [
//   <span key='something'>label</span>,
//   <h1 key='otherthing'>heading</h1>
// ]

reactStringReplace('These are my {} and {} and {} values.', /({})/g, (match, i) => {
  // odd index numbers
  return nodes[(i - 1) / 2]
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions