I need to dynamically build a React component based on consistently structured text in an unknown order. How do I replace the placeholder numbers (identified in some consistent way, see below) with corresponding components that consume the placeholder as props?
const text = "some (1) arbitrary amount of [2] text";
return (
<div>
some
<Component1 var={1} />
arbitrary amount of
<Component2 var={2} />
text
</div>
)
The placement and order of [] and () is not consistent, so that:
const text = "[2] some arbitrary amount (1) of text";
return (
<div>
<Component2 var={2} />
some arbitrary amount
<Component1 var={1} />
of text
</div>
)