I developed a React component representing a window that allows the user to interact with a chatbot. This window opens when the user clicks a button. Now, I want to make this button available in any site or application of my choice. The first idea that came to mind is to associate a URL to this button so I can call it in our site or application by simply creating a link like:
Chat with the robot .
I find the idea functional but I do not know how to associate a URL to a component in React. I looked at the React-Router side of what I understood it just allows to create the navigation between component of the same application but I do not know if its URL can be accessible outside the application where they are created.
Do you know any tips for solving such problems?
And if you have ideas other than linking the URL to the component, I'm interested.
Thank you in advance !!!
You cannot use a react component by pulling it in as external code. react-router works by wrapping you application. Any component you want to use has to be part of the actual codebase.
Related
I need to create a popup message component which gets user feedback. Is there any way for me to develop a component like this (some type of dialog/modal probably) without making a new page to test it on?
Like, is there any way for me to develop this individual popup message, or other small components, in isolation, and then later attach them to a larger page component?
Sure you could use an online editor like codesandbox
Or you could use a dedicated create react app for testing / developing a component alone
You can just make the popup component, and add it into your App.js to see if it works as far as working on local workspace goes. you can also try some sort of virtual code editor like codepen, stackblitz, codesandbox, etc, then copy the code over into your workspace.
I'm currently developing a React SPA with a Spring Boot backend API.
For one use case i need to create a dynamic link which contains login credentials for a one-time-User. With this link a user needs to be able to login to the SPA and use it further from outside the application.
This is the first time I'm working with a SPA.
What is the best way to achieve this goal?
I would really appreciate some ideas.
best regards
You probably need to use a Router (like React Router). These cause different components to be rendered in React depending on the current URL, and from there different code can be run (likely from event handlers or useEffect if you're using function components).
I'm a bit new to React.
My company is starting to build a product than needs to be customized by any client.
Is it possible to create a component (let's call it plugin) and deploy it into a folder in a production environment and that component being rendered without recompiling the entire app?
e.g.: I have a form and i need another form calling a client's API that renders some info and then pass that info to the main app form. That 2nd form should be this kind of plugin, due to the fact that it depends on the clients' APIs for the component to render a table, a chart, or whatever the component itself renders.
I've been googling and i haven't found a solution yet.
Thank you all :D
We will be doing our first project using React.
It will not be a Single Page App, but a Multiple Page App.
What I'm trying to figure out at the moment is : what's the difference between a component and an app.
If I only use components, can I still use Redux to have some state management on the current page ? Or do I need an app for this ?
Thanks for the information you can bring !
THoma
There is no special object called "React App". React Components build an "React App" by coming together.
But React Components are formed like tree structure. That means each component have a parent component so you can create a React Component that named "App" and can put another components inside it.
You don't need redux for state management in React Components.
I hope the answers have helped.
Your app may contains a single component and still it will be a react App. If you are using multiple components in a page you can still use react-redux. Redux is basically a container for your states and let suppose you need some state from one component to be consumed in another, Redux provide you a mechanism to make the communication efficient and predictable.
You can also look at the React Context APIs as an alternate to Redux.
An app is simply a component that holds the root of the work you are trying to do. For example an App may have the navigation menu, testimonials, adverts, content, login avitar etc.
If you are making a single App per page (For example a testimonial) then you would still have a SPA. For example, adding testimonials, searching, editing.
You should only use Redux if you are using a SPA with lots of different parts with data in common. If you are making a one-app-per-page and there is no cross over in data then you can simply using Reacts State/Props to hold your data.
Redux is good, but it forces you into a complex path your should try to avoid. If you find yourself wanting data from different domains (customers address and a list of testimonials) then you should use Redux.
If this is a new applications (green) then I strongly recommend you build the whole thing within a SPA using React-Router to control components. you can use frameworks like Next.JS to ensure the site remains small in size (dynamically loading script only when required).
I have a use case where I want to open a react application in new window whenever user clicks a button. I want to pass some props to the react application. Presently I am sending the props via appending them to URL.
Example
Let's say my application is accessible at lomoto/car. I am currently sending parameters via lomoto/car/value1/value2. I am accessing these properties via props.match.params.prop1 and props.match.params.prop2. I am using react-router v4 for routing.
Is there any other recommended way of achieving this?
You can save the state to the browser's local storage and then access it from any tab.
In this egg head video Dan Abramov explains how to make use of the browser's local storage for redux.
You can use a similar approach with or without redux.