1

I am trying to create a React component and import it through a git URL.

My question is, how should the component be created? How should I import it?

I didn't find much information

I've been reviewing this response How can I import a component from GitHub repository

For example, i have this component

import React from "react";

function Title() {
  return (
    <div>
      <h1>Sample Importing</h1>
    </div>
  );
}

export default Title;

To migrate it to the new git repo, should I initialize the project with CRA?

How do I give the directives to then do

npm install bitbuketurl..

import Title from '....'

nawelittle
  • 293
  • 2
  • 3
  • 8
  • You use npm or yarn or `git clone` to *copy* a repository, or some file(s), *from* some hosting site like github or bitbucket. Once that's done you have a *file* and you can import it like any other file. (If possible, don't use Git directly here - package managers avoid dealing with the low-level details.) – torek Sep 16 '22 at 02:42
  • Yes, I have my component in the repository. How to import this in the project? Do I need a specific export? – nawelittle Sep 16 '22 at 19:45
  • All I'm saying here is that you don't "import X from ", you "import X from react" for instance (just as you've shown above). "React" is not a URL, it's the name of a module or package or whatever. (There are systems that deliberately correlate packages and URLs, e.g., Rust and Go tend to work this way, but JavaScript isn't one of these.) – torek Sep 17 '22 at 03:52
  • I want to create a React component in a bitbucket repository, and import it into another project... – nawelittle Sep 19 '22 at 17:39
  • You can create React components: you write files to do that. You can store those files in a Git repository: you use Git to do that. You can copy the Git repository around, using GitHub or Bitbucket or GitLab to host it, and `git clone` to grab yet another copy of it, and `git checkout` to get the files out of some commit. And then you can import the files you checked out. But you can't import directly from a Git repository: you must first clone the repository and check out a commit, so that you have files. – torek Sep 19 '22 at 18:01
  • Git is a set of tools, not a solution. Just as you don't go to Ace Hardware and buy a completed project, you don't use Git to complete a project. You use Git as a set of tools (to do work with files that relate in some way to each other and need version management), and that's all you do with Git. – torek Sep 19 '22 at 18:02

0 Answers0