Use react in laravel module - reactjs

I'm trying to make a modular web with Laravel modules, and I want to use react to build Frontend, I can use react in the root folder already, but I canĀ“t do it inside a module.
I run php artisan ui react to install react in root folder, but this command does not work inside a module, so i dont know how to install react inside a module.
Any idea of how to do it?
I want to use react in each module i have and another modules I'll add in future.

Related

How to export React Native components created in storybook for it to be used in actual app?

I understand we can create and test React Native Components in isolation in Storybook. But how do we export/publish the components to integrate in our app?
In React -
I used react-docgen that will allow me to create and document components as a standalone project
Then I will build and publish my doc app as a package to npm registry and npm install as dependency in my app to import those components
How do we do same in Storybook with React Native? Should I -
copy files/code of tested components in my actual app?
export everything just in stories folder and build and publish as package and install as dependency in my app?
Install storybook in my actual app? But I guess that's not an option as storybook is supposed to be run as standalone app in itself
May be I am missing something obvious as no tutorial/article/doc talk about how to consume the created Components in final apps? Can someone please shed some light? Thank you.
Ok, someone finally said this in a tutorial-
Once you find the component and the state that you want, you can see the source code you need to place in your application to get the exact same functionality
So, after all it will act simply like a UI library documentation from where you need to copy code from example and cannot add stories as dependency to your project.

How to build React components to be consumed by HTML application?

I have a React project created with npx create-react-app where I implemented a handful React Components. I don't really see this project as an "React application", as it's just a personal library of Components I consume in another project, an HTML web application rendered using server-side technologies. My goal is to gradually replace parts of this application with React components. I don't really envision it becoming a single React application, my plan is just to replace the parts I think make sense to be developed with React.
I have no issue implementing these components - I'm using Storybook to organize the independent modules. But I'm struggling with the build process.
If I run npm run build I create a single application, based on the original React application code bootstrapped by create-react-app, which I essentially abandoned in favor of the Storybook setup. If I add the files generated by npm run build my project, I can't get React to render my components properly.
I managed to get a manual build process to work:
In my HTML project I add https://unpkg.com/react#16/umd/react.production.min.js and https://unpkg.com/react-dom#16/umd/react-dom.production.min.js
For each of my React components source files, I run npx babel --presets react-app/prod src/MyComponent.js -o build/mycomponent.js
Then I combine all the npx babel outputs in a single components.js file, adjusting some repeated functions that appear on the top of all files, and suppressing the import and export statements.
I load the component.js file in my HTML project, and I can create my components using plain JS:
ReactDOM.render(
React.createElement(MyComponent, {param: value}, null),
document.getElementById('myComponent')
);
Is there a better process to build my components to a single JS file I could consume in my HTML application?
As you expected, the project should be a reusable module/ UI library (say the name is my-ui) for other projects. I did the similar thing before and just introduce my approach here. First, export the components as normal. Second, create an index.js. Third, import and export those components you exported. Fourth, if you are familiar with webpack, use index.js as the entry in webpack.config.js to bundle the entire project as one file. You can publish this package, or just use it locally.
Then in other projects, import my-ui, you can use any component exported from that module.

How can I apply Next.js to a React project created with create-react-app?

I'd tried to figure out how to use server side rendering (SSR) on my existing react, and I found Next.js which is a SSR framework for React.
Also, there is create-next-app to easily create Next.js app like CRA. As I already have my existing React project, I need to make it compatible with Next.js. But, they have quite different project architecutre.
I attached two architectures of create-next-app and create-react-app each with images below. As Next requires the folder pages, I feel like I need to move my components in that folder, but I'm confused about src and public folder in create-react-app.
Can anyone help me how can I apply Next.js to an existing React app?
create-next-app
create-react-app
You can install Next js by adding 'next' package to your CRA. However, you would have to refractor part of your codebase. The src folder should contain a subfolder called 'pages', consisting of your paths.
Visit the Next JS Documentation for more

How to create a React app without webpack and Create-react-app

without using webpack and create-react-app how to create a React app
i would like to use following in my react application
1.redux
2.react routing
You can simply copy the cdn and implement your component to the project. That is if you have already a web page and you want to implement a few components with reactJs. Check this page has your answer.
https://reactjs.org/docs/add-react-to-a-website.html

integrating react project into another react project

I am very new to react. I grabbed the petclinic project from github (https://github.com/spring-petclinic/spring-petclinic-reactjs) to run it and understand how react works. I want to add plugins to this project (plugins are other react projects as I understand), The plugin I want to add is a datatable (https://github.com/rishabhbits038/react-tabelify) which is another react project. My question is how to integrate one react project inside the other. in jquery it is direct, just including the .js file in the project but in react it does not seem that obvious.
From inside the petclinic project, run
npm install react-tabelify
and import the component you want use as:
import Tabelify from 'react-tabelify';
should work, as the second library is registered with npm

Resources