Answer the question
In order to leave comments, you need to log in
How to pass to props?
Good afternoon.
Tell me how can I pass some props to a component that is called like this:
const mapper = {
'{user}': <UserAddon />,
'{post}': <PostAddon />,
'{group}': <GroupAddon />,
};
export const ContentRender = () => {
const content = "{user} опубликовал(а) {post} в группе {group}";
return (
{content.split(/({.*?})/g).map((child) => (
<>{child.startsWith("{") ? mapper[child.trim()] : child}</>
))}
);
}
Answer the question
In order to leave comments, you need to log in
export const ContentRender = (props) => {
const content = "{(props.user} опубликовал(а) {(props.post} в группе {(props.group}";
return (
{content.split(/({.*?})/g).map((child) => (
<>{child.startsWith("{") ? mapper[child.trim()] : child}</>
))}
);
}
// вызов компонента
<ContentRender user={mapper['{user}']} post={mapper['{post}']} group={mapper['{group}']}>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question