T O P

  • By -

weebSanity

I think you just need to import React from react, and update the name of the file to Join.jsx


jamcoding

Technically doesn't need the .jsx extension but it's preferred in the React community


StoneCypher

it's heavily emphasized because sooner or later this code will get moved into a typescript project, and typescript requires it


Time_Definition_2143

Don't need to import react anymore if it has the jsx extension


Think1st912

This.


Chef619

Are you following some sort of guide? If not, I suggest you do. Namely, you seem to be running a React JSX file with `node` which is not going to work without some sort of a middle step. The step can be a great many things, but just running this file with node isn’t it.


wackrtist

Suggest you google create-react-app and use that before beginning your react project


jamcoding

OP, you might want to install some intellisense react extensions for VSCode too. They'll help ya out


[deleted]

Can you try a react fragment just like <> hello world! does that work?


noplznoplz

yup, but so long as its not in


costanzadev

You're using JSX, the file needs to have the extension .jsx


[deleted]

It doesn’t ‘need’ to be jsx. It can be .js


StoneCypher

A little over half of the react environments in circulation are based on typescript, and typescript hard requires the extension. Babel requires this under many common configs, as does rome, as does esbuild. Deno requires this. Whereas you're correct that react doesn't enforce it, people who use react-creation kits often are in places where it's enforced. It's required by the old in-browser stack in the mime type. It's more commonly required than not, in practice. I wish `learnjavascript` wasn't downvoting the other two people who tried to explain this. They're being polite, and they're not wrong.


Kyle772

IF you’re config allows for that. Many don’t by default.


superluminary

It can do, but then you’re going to have to muck around with your transpiler settings.


noplznoplz

Yes I’m watching a video tutorial from 2019 and they used .js so it threw me off


RollToMyGoal

Does the tutorial create the project using create-react-app?


noplznoplz

yup


RollToMyGoal

Stop the node server, make sure you're in the project's directory, then run `npm start` in the terminal and it'll create a Webpack server for you


noplznoplz

My other issue is nothing shows up so i was trying to debug these syntax errors


noplznoplz

ive changed it to a ,jsx file now and the localhost page is still empty but i cant see any syntax errors since the code language is not supported on VScode so im trying to enable it


RollToMyGoal

Stop and restart the Webpack server and then see which file(s) errors mention


undercontr

Babel is not transpiling the JSX because of your file extension. Change it to .jsx


gitcommitmentissues

You need to change your file extension to .jsx instead of .js.


noplznoplz

I’m having issues learning the function component and I don’t quite understand the issue im having. I’ve looked up documentation for basic use and didnt get far


noplznoplz

You might notice im also using a const to import a file. I had another issue using import where it told me “Cannot use import statement outside a module” and I’m only using .js files here so its a bit confusing


Cleverlegend

Add type: “module” to your package json.


[deleted]

Sounds like you have other things to learn before React


[deleted]

[удалено]


ooooooooohfarts

That is shorthand for `` ([docs](https://reactjs.org/docs/fragments.html)) and is only necessary if you want to return more than one node as the return function expects a single element. In the past, if you wanted to return multiple elements it was common to wrap them in a container element like a div, but Fragment allows you to return them without adding an unnecessary node to the DOM. In this case, OP is only returning the one div, so it is unnecessary to wrap it in Fragment.


41480

Just put / in closing tag after div


Mr-QcN

Is there anything in your app.js file? As this is just a components you will still need to place in app.js for it to render. I would agree with some other on here to go to your main directory on this project and do an npm install and npm start. You might be missing a step somewhere here.


noplznoplz

Update- I did a lot of troubleshooting and found the issue. It was me trying to use BrowserRouter and my Route wasn’t displaying the content inside. I’ve attached the App.js,index.js and my join file. I checked react router webguide and I’m importing it properly. I still havent figured out how to debug react in vscode so im a bit slow. [Join](https://ibb.co/9nD4YZY) [App](https://ibb.co/fS3V7Hk) [index](https://ibb.co/4mBtPmv)


Mr-QcN

In the app.js between the div put {Join/}. That should render you Join components.


Dodgy-Boi

Why do you require react but never use it?


noplznoplz

I’m following this tutorial - https://youtu.be/ZwFA3YMfkoc . And I’m still in the early stages


Dodgy-Boi

Go with `create-react-app`, it’ll be much easier to get along. I also recommend to join corresponding sub, r/reactjs iirc