G
G
Georgy Kuznetsov2021-12-18 01:53:04
React
Georgy Kuznetsov, 2021-12-18 01:53:04

How to use React components with specific parameters using TS?

Let's say there is such a React component in tsx format:

export const Comp = (a: string) => {
    <div>
        <h1> {a} </h1>
    </div>
}


How to use such a component (by passing the necessary parameter to it) in code like this (also tsx):
import {Component} from 'react';
import './Main.css';

class Main extends Component {
    render () {
        return(
            <div className="Main">
                
            </div>
        );
    }
}

export default Main;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-12-18
@Aetae

export const Comp = (a: string) => {
    <div>
        <h1> {a} </h1>
    </div>
}

This is not a react component. A react component always has a readonly props object as its first argument. There cannot be a line.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question