why all react component is in one file jsx? - reactjs

I'm beginner in react and now I check a project that is like crisp and all off react component is in a one jsx file. I studing react and test some project but None of them is'nt like this.
this project dosn't have any ClientApp folder and subfolders.
this project is asp core and have signalR . file jsx use in a view action and run nice.
and how I can split componnent from main file jsx. I should create Appclient folder or not.
[![enter image description here][1]][1]

Related

Create react library - assets bundle

I have created a react typescript project using "create-react-library".
The project export a component, let's call it "A".
The "A" component render an svg image which is inside the component folder.
But when i compile the library project (using microbundle), there is no assets in dist folder.
And as a result, if i use component "A" in a test example project, i cannot see the svg image.
I have not found any example which handle this scenario.

Problems exporting a React app as a npm module that contains a SVG picture

I have a React application created with create-react-app. I have built and published it as a npm module. Everything works fine, I can use the components I have exported etc. The one problem I'm having is that pictures (SVGs) in my case, won't be displayed in the application that have imported that module.
The picture below shows the folder structure of the project being exported and published as a npm module.
The picture below shows the folder structure of the imported module while being used in a project.
The picture below shows the component I export.
The picture below shows the compiled exported component.
The picture below shows the component above being used in the project that imports the module.
The pictures below show the app that imports the module failing to render the picture.
Do you guys have any idea of why the picture is not loading properly?
I think it is because of wrong importing SVG -
per docs you need to import SVG like:
import { ReactComponent as Logo } from './udilia-logo.svg';
also it may be due wrong version of react-create-app
this feature is available with react-scripts#2.0.0 and higher, and react#16.3.0 and higher.

officejs react - how do I add another page?

I have created a Microsoft Office Add-in React (TypeScript) Project using yo office
How do I add another page? I want to create some additional UI which pops up in a dialog (ie. displayed using Office.context.ui.displayDialogAsync) so no need for loading officejs
I tried to use react-router but I didn't manage to get it working... The way index.tsx works is a bit different from the normal create-react-app template that most tutorials use.
I did this by adding:
a new tsx file for my page
a new HtmlWebpackPlugin in webpack.common.js with a new chunk name
an entry in webpack.common.js which links my tsx file with my chunk

ReactNative Webview

React js : I am trying to open my react js production build folder under which the one html file is placed after run npm run build.
React Native: I am using react-native-webview Plugin for open the same index.html file. For android I placed this folder under assets.
The codebase giving me error File_Not_Found.
The build html file is minify html file. When I try to use any url here or any development plain html it is working fine. For this minify file it is not working.
Please help.
I am using this code for android react native.
if(isAndroid){
console.log(isAndroid);
return (
)
}
I want to open production this react js build folder html file in react native webview.
Create an object
const index = require('./assets/index.html');
set your source to the object instead of using a uri.

Embedding full react application into an existing web page

I'm looking to embed my react application into an existing plain html / javascript website. What I've found so far is that you are only able to embed individual components into existing websites, not entire react applications.
Naturally I have an app component which contains the entire application. Am I able to embed the full application by embedding this component? My concern is all the modules I'm using (e.g. axios, bootstrap) will break.
I've been looking for a good tutorial on how to do this but I'm not finding many examples of trying to embed the entire application into an existing page.
My understanding of how to do this, is to reference the react javascript source links in the html page head, possibly also babel although its unclear to me if babel will work. Then we can use the renderDom method like we normally would.
On page load can I run my index.js file to insert my react app component into the dom? If this would work, are there any issues with file structure, file updates I would need to take care of?
If I'm driving off path out into the wilderness and there is a better way to handle it I'm open to suggestions. I'm just looking to see if someone else has experience doing this before I start down a bad path.
I was able to embed my full react application by doing the following...
I built my react app production files with npm run build
I copied those files into the existing web project at the root level
Then I opened the index.html file generated from npm run build and copied the scripts in the head and body sections to the page I wanted to drop in my application
Finally I added a div with the id root (this is what my renderDOM method is looking for) where I wanted my application to appear on the existing web page.
That was it. Super easy, thanks for the help!
Just wanted to add a quick additional approach here.
If you already have a Flask app and you're trying to put React components or an app (so the base component of an app) onto an existing HTML page in the Flask app, basically the only thing that you need is Babel, unless you are able to write React components without using JSX (so in plain Javascript) in which case you'd need nothing.
Step 1: To attach Babel to your project, you'll have to grab the Babel node modules which means your project will be associated with NPM for the sole purpose of using the Babel functions. You can do this by running the following commands in your project root directory (Node.js must be installed):
npm init -y
npm install babel-cli#6 babel-preset-react-app#3
Step 2: Once Babel is attached to your project, you'll have to actually transpile the existing React component .js files from JSX into plain Javascript like so:
npx babel --watch (jsdirectory) --out-dir (outputdirectory) --presets react-app/prod
where (jsdirectory) is the path to the directory where your React component files written using JSX are, and (outputdirectory) is where you want your translated files to show up--use . for (outputdirectory) to have transpiled files appear in your root directory.
Step 3: After the plain Javascript versions of your React files appear, make sure they are linked to your HTML page instead of the original JSX-utilizing files (replace the original script tag's .js file)
Step 4: Make sure the HTML page in question is linked to the .CSS files you want (they will modify the transpiled Javascript in the same manner as they did the JSX files in a project made using Create-React-App because the class names are the same) as well as the required React resources:
<script src="https://unpkg.com/react#16/umd/react.production.min.js" crossorigin></script>
<script src="https://unpkg.com/react-dom#16/umd/react-dom.production.min.js" crossorigin></script>
After you do those quick steps your React components should render no problem on that page in your Python-Flask application.

Resources