I'm trying to implement a feature, when a user comments and makes a special reference I want to replace that reference with a react component. Use this as an example:
This is my first post on this app, check out these 2 games @apps_blackjack & @apps_weather.
The keyword to look for in a string is anything that starts with "@apps_" and then get the second keyword "blackjack" or "weather" and returns a component while passing down that variable to the component.
This is what I'm expecting:
<Link className='post_link' to={props.app}>
Link
</Link>
The {props.app} variable would be blackjack or weather in this case. The final outcome would be:
This is my first post on this app, check out these 2 games
<Link className='post_link' to='blackjack'>
Link
</Link>
&
<Link className='post_link' to='weather'>
Link
</Link>
I'm thinking about using string.replace() but am not exactly sure how to implement it as it is much more complicated since we need to also preserve the keyword that comes after the @apps_ keyword.
This is somehow similar to the feature that Facebook uses in the messenger app to highlight user names.