0

I'm unsure of some of the terminology for React elements so please excuse me if I'm off the mark.

My Issue

I've set up this component in my React web app.

const Title = ({lineContent}) => {

  let line1 = useRef(null);

  return (
    <h1 className="page-title">
      <div ref={el => line1 = el} className="line">
        {lineContent}
      </div>
    </h1>
  )
  
  };

and I'm pulling it through to a parent component:

<Title lineContent="Text for line one"/>

I want to wrap a <span> around a word within the lineContent="" attribute, so I can change it's colour.

<Title lineContent="Text for <span>line</span> one"/>

But it currently renders out the <span> tag as if it was standard text.

Is there any way of setting this up so that the <span> is recognised as HTML so I can style it in css? Any direction would be great appreciated!

1 Answer 1

1

Yes, just pass the element it self instead of a string:

<Title
  lineContent={
    <>
      Text for <span>line</span> one
    </>
  }
/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.