A
A
alex4answ2021-01-21 20:41:29
React
alex4answ, 2021-01-21 20:41:29

How to pass a component to render as props?

Good afternoon, there is a "Link" component, you need to add it, it is possible to pass a component to the props that will render the link.

There are no problems with this, the problem is with the "standard" component for rendering, here is the component code:<a />

function Link = (props) => {
  const Component = props.component || <a/>; // тут проблема

  return (<Component
    {...props}
   />);
};


How to pass a standard html tag - component to the Component variable?
So far I only know this:
const Component = props.component || (props) => <a  {...props} />;


Please tell me, the task is simple, but I don’t know how to call it to google it, the render props is slightly different

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2021-01-21
@alex4answ

props.component || <a/>

props.component || 'a'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question