Is posible to use Vanilla HTML in a React web app? - javascript

I'm currently working in a React web app and to save time, a work collegue helped me with the landing page. He did it using vanilla HTML, CSS and vanilla JS.
My question is, can I use that landing without having to adapt it to react? I know I could wrap all the code in a div and go on. But the JS librarys that he used, have to ve adapted.
I tried doing a npm build, create a index.html and place the build folder under it in a folder called "trade". I was trying to create a structure like: "http://ip-server/" is the index.html that I created. And "http://ip-server/trade/" is the react app. I used Docker with Nginx for it. But it didn't seem to work. All I could reach was the index.html, never the build folder.
Am I missing something? Or is it better to adapt the landing?

I would use the "div" technique to adapt the landing page. For that you'd could use "dangerouslySetInnerHTML" as pointed out here: https://reactjs.org/docs/dom-elements.html
function createMarkup() {
return {__html: 'First · Second'};
}
function MyComponent() {
return <div dangerouslySetInnerHTML={createMarkup()} />;
}
And then you'll need to research how to make the third party javascript from that landing page work in React in case per case basis. This will be useful for you also for future cases if you can afford to invest the time now. I hope this helps!

Related

Is react easy to integrate with already-created html and css files

I'm working with some developers to create a website, and I want to know if React will work if I hire someone to create the html and css first, and then have another person integrate react with those templates
Is react integratable in this situation, or does react have to be used from the get go? I am a python programmer, so I have no clue how react works lol
The main advantage of React is being able to generate HTML based on JavaScript code, if the HTML code is already done I'd find it kind of pointless to use React.
I am just a 2nd year student but I'd recommend to use React from the get go.
It should technically be possible to integrate react with already existing html/css files, just like you can manually alter the html and css files in your react project’s public folder, but you dont really provide a good reason for doing so. It might be easier, and more sustainable for maintaining the project to simply move your existing Html into a react project. If you dont have an actual good reason to use react for this project (like for example having primarily react-experienced developers on the team or needing to use specific react libraries and functionalities), there is no real harm in developing a website with plain html, css, and js.

Additional JavaScript tags in next.js

I very recently started programming with react & next.js (previously I was using node.js)
and I made my first application, but on inspecting the page I saw a lot of additional JavaScript (image given below)
here's my directory:
here's my index.js source code:
export default function Home() {
return (
<div>
hello world
</div>
)
}
Here's what I mean by additional JavaScript
Since I've been using node.js I'm not very familiar with all this JavaScript being placed in the code automatically,
could someone please explain what all of this is, where it's coming from and why it's necessary?
next.js or react.js are libraries to create single page applications, you don't need to write html manually now, everything will be generated using javscript. these files are just internal library script files generated by webpack tool in chunks, you might be thinking, why is it so, like we can also store these all scripts into one file, but actually webpack breaks modules into chunks, so that it will only load these files whenever needed for optimization of web performace.

How do I implement a html/css/js theme into Vue properly?

I got a bootstrap theme that consists of HTML, CSS and Javascript. Now, I want to implement it (or let's say make it functional) in Vue. I have my index.html file that contains the container and it works. Now, my theme does have an index.html file as well. I just thought I can copy the whole file into the Vue-index.html and add the div with the id "app" around the area that changes the content. But it does not work. Basically, Vue does not load any external css or js files even though I reference them correctly (with relative reference using the dot: ./assets/css/style.css). It works inside a .vue-file (i.e. component) but not inside the index.html. What do I do wrong?
Yep, beginner here.
When you put them inside your index.html they are not compiled.
You can read about it HERE
Your index.html is something called a target. Vue uses this file as a mounting point for the rest of the application, so it's kept relatively clean, most likely with just metadata and a DOM mounting point. It works by loading the index.html in the browser and then mounting your Vue application on top of it.
If you're trying to apply some styles to a Vue application/components, your best bet is to modify *.vue files inside the app source of your Vue project (typically, /your-project/src). They will contain snippets of relevant sections/components alongside their logic (JavaScript) and styles (CSS/Sass), provided your project uses Single-File Components format.
For future reference:
It's hard to offer a solution without knowing the structure of your project, what type of components you are using, or even having code samples to get an idea of how things are working inside.
We'd need more information to be able to help you more accurately, so maybe you could create a lightweight demo on an interactive platform like codesandbox.io?

Partial Implementation of create-react-app to a website

I'm currently developing a website/webapp (I don't really know the clear distinction between it) for my school project. Initially I was planning to develop entirely through just HTML/CSS and JS, however, my adviser told me to use react framework for parts of the pages instead of just doing it with Java for the sake of simplicity. This has been really messing me up since I have no background in web development and I'm confused in general.
I currently have all of the HTML pages styled with CSS, and I was able to transition part of the web-app to react using create-react-app. However, I have no clue how to connect these two.
I created the my-app folder inside the main directory which contains most of the HTML folders, but how would I go by to
1. Access the react app from the HTML page?
2. Access the HTML page in the main directory from the react app?
Following is my directory as a reference
mainDir
|_____bunch of html files
|_____css //contains all css files
|_____img // contains all images
|_____my-app
|____all the files created by create-react-app
Approaches I have tried:
- using the in the HTML pages in the main directory to jump to index.html in the my-app file to load the app
- changing the file path on the tag inside the App.js render() function of each class to something like ../../welcome.html which is the relative path to an HTML in the main directory.
Thank you for your help in advance. I'm welcome to any and all suggestions! If there isn't enough information to assess the situation, please let me know!
Checkout
This Example source code, from React.js: "Add React in One Minute" guide.
What is it?
It's a super bare-minimum implementation of React using:
1 x .html file
1 x .js file
Given your current setup, I'd say it's a lot simpler than trying to incorporate create-react-app.
Let me know if this helps; I'm happy to delete this if it's not useful.

Integrate React app created with create-react-app into an external application

I'm using create-react-app-typescript to create a react application. What I'm trying to do is to build the application, then include the resulting js and CSS files into another application (which is a very old application that doesn't know anything about React or any new JavaScript features)
My problem: I want to be able to pass information to my React application; for example, I want to specify an array to be used to display information, but the issue is that as soon as I add a <script> tag to React's js file, it will try to create the application under the target div element.
Not sure if it's a good idea, but I try to avoid ejecting my React application as much as possible so that I wouldn't need to maintain everything myself.
One solution that I thought of was to create an item in localStorage and then read it from my React app, and this somehow solves the issue, but is this a good way to do it?
And then there's another issue: I want to be able to pass a callback from the external application to be called from my React app to cause something to happen in my external application, and this cannot be done using localStorage
Any help or tip is deeply appreciated,
Thank you
You don't have to eject the project at all. One possible solution (maybe not the best) is just to change your index.js to expose your application. Thus instead of directly "rendering" the app do something like following
// needed imports
window.startFromOutside = function(element, callback) {
ReactDOM.render(<ReactApp cb={callback} />, element)
}
That way you can bootstrap your react application from outside passing any properties you want.

Categories

Resources