Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

React: How can I import a Title-Component which will be commonly used

I wanted to import a title-component in order to apply it throughout the app.

Here’s the title-component:

import styled from "styled-components";

const HeadTitle = styled.h2`
    font-size: 40px;

`
const Title = () => {

    return (
        <HeadTitle></HeadTitle>
    )
}

export default Title;

And in the component where I want to use it, no text is showing up:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

return (
        <div>
            <Title>Best</Title>
        </div>
    );

I want to see "Best" with font-size 40px – how can I do that?

>Solution :

On the reusable component do:

import styled from "styled-components";
    
    const HeadTitle = styled.h2`
        font-size: 40px;
    
    `
    const Title = ({text}) => {
    
        return (
            <HeadTitle>{text}</HeadTitle>
        )
    }
    
export default Title;

On the component that’s to use the reusable component do (I’ll use ‘Home’ as an example):

import react from "react";
import Title from './Title.js';

const Home = () => {

    return (
        <Title text="This is home" />
    )
}

export default Home;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading