Unable to get past the 'React App' main screen - reactjs

I'm not able to get a 'react' application beyond Screen with the "atom icon" and "learn React" link.
There is a message saying 'Edit src/App.js and save to reload.'
But there's nothing giving any information or clue about what changes need to be made to the App.js file, what configuration or other settings to check (and what the values should be), etc.
What do I need to do to get a React app to actually work?
//=========================
// BEGIN App.js SourceCode:
// ------------------------
import React from 'react';
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
// ----------------------
// END App.js SourceCode
//=======================

The changes you need to make to App.js is the code for the initial page of your React App.

Replace your code with this, and change the "Hello":
import React from 'react';
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<p>Hello</p>
</div>
);
}
export default App;

Related

launching ios simulator with expo, receiving 'Unable to resolve module'

Please see image below to assist. I can't seem to work out where i'm going wrong?
This is my first time using expo so I am fairly confused with it. I'm trying to launch my react app on the ios simulator but receiving the error message;
iOS Bundling failed 18ms
Unable to resolve module ./App from /Users/luke/Desktop/Projects/simulate/index.js:
None of these files exist:
* App(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
* App/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
1 | import { registerRootComponent } from 'expo';
2 |
> 3 | import App from './App';
INDEX.JS
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './Components/App/App';
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
APP.JS
import logo from './logo.svg';
import './App.css';
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
This is happen because you deleted your App.js from your tree, so your project is trying to get access to a file that doesn´t exist
You must have something like this:
enter image description here

Getting Error while adding a component to App component of React

import React, {Component} from 'react'
const Greet=()=> <h1>Say helllo</h1>
export default Greet;
This functional component i've created and imported in App.js
import logo from './logo.svg';
import './App.css';
import './Components/Greet'
function App() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
<br></br>
<button>Submit</button>
</header>
<Greet/>
</div>
);
}
export default App;
But getting error in chrome web:
**src\App.js
Line 24:8: 'Greet' is not defined react/jsx-no-undef
src\Components\Greet.js
Line 7:16: 'Greet' is not defined no-undef**
New to React Helpful if someone can help me with this.
const greet=()=> <h1>Say helllo</h1>
Try Greet instead of greet
Also in your App.js write in this way
import Greet from "./Components/Greet";

<img> tag not loading CodeSandbox.io

I have been trying add an image using the tag on CodeSandbox.io. However, every time I try to add it, it doesn't show and just defaults to the alt tag (Displays logo).
import React from "react";
import logo from "./logo.svg";
import "./App.css";
function App() {
return (
<div className="App">
<header className="App-header">
<img src={require("./logo.svg")} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
You can checkout my code and a live demo at this codesandbox link
Codesandbox doesn't support directly importing images. Instead, you can either add them as static uploads and reference their uploaded URL or import them as React components:

Just adding useState hook statement causing component to rerender

I have created a basic create-react-app and added the below statement
const [stateA, setStateA] = useState(false);
and I have put a console.log inside my component.
The complete component code is
import React, { useState } from 'react';
import logo from './logo.svg';
import './App.css';
const App = () => {
const [stateA, setStateA] = useState(false);
console.log("rendered");
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
export default App;
It is showing "rendered" twice. Can any one tell why this is happening ?
If you notice index.js (as create-react-app now uses React.StrictMode by default ) file you may have a wrapper called React.StrictMode which is responsible for this extra re-render. The wrapper will invoke render, constructor and other lifecycle methods to detect side effects. So this is expected.
You can read more here: https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects
Hope this helps!

Can't find module TS2307 in React

import React from "react";
import logo from "./logo.svg";
import text from "./compiler/test/index.txt";
import "./App.css";
const App: React.FC = () => {
// const compiler = new Compiler("../test/index.jack");
// compiler.save();
console.log("text: ", text);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
};
export default App;
I'm using react-app-rewired to override webpack configuration, without ejecting.
This component reads a .txt file and logs its content, but there is an error, Cannot find module './compiler/test/index.txt'. TS2307 in the third line of import.
As my comment seemed to resolve the issue, here as an official answer:
You probably just need to declare the type .txt somewhere in your typescript definitions. For create-react-app, this would be in react-app-env.d.ts. E.g.:
declare module '*.txt' {
const content: string;
export default content;
}

Resources