Common components issue in react.js - javascript

I've made 3 sets of carousel each with different API data passing into the components and a common component of the navigation button (previous and next button) I'm using to navigate but on clicking on anyone all carousel working simultaneously.

Related

React - possible to use the back button in browser in a form

I'm trying to build a dynamic form where the data sent from the server will be rendered by the client. The form will have X amount of steps, decided by the data.
I have my component Form rendering X amount of components Steps.
My problem now is that since it's all the same component, Form, there's not possible for the user to click on the back button to go to the previous step in the Form. I somehow need to keep my URL in sync with my Form/Steps.
What would be the best solution to this problem? Using HashRouter and using Route with "/:id/:step"(how would this work)? Pushing the routes in automatically using useHistory-hook?
The most simplest case as I think is to create parent component with state step and change it when a user go or return to step. Based on step you should render the appropriate step.
A css solution would be to break the form into sections and show 1 section at a time, when some one clicks on the navigation buttons of the form a state update triggers another section to be shown while hidihng the current one. This can be done using CSS transitions, you can look into react-transition-groups to make css transitions with react easier

Redux or simple React to handle navigation

I am very new to React and Redux and I am currently trying to wrap my head around how states are shared through the UI.
I have a pretty simple use case.
Picture a container with three columns:
A left Side Menu with four buttons
A central content section
A right container with some other content
When I click one of the four buttons I want three things to happen:
The class on the button is updated so it has borders
The class on the other buttons is updated so if they had been clicked before their border class is removed
The content in one part of the middle section is updated. This content requires data from the backend (Django Rest) to be fetched
Here are my questions:
Should I separate this interaction into a UI only concern and a Data driven one or handle both with a single state?
Because the buttons share a parent component but they do not with the central component, would I be better off using Redux if I do not want to define the state at the very top level of the Container?
Because I am new and Hooks seem to be the way to go I am trying to use hooks rather than classes, does it still make sense to separate components and containers?
You can use react-router-dom library to achieve want you want.
for your left side menu you can create active class in css and then check for current route with location.pathname property of react-router-dom and if it is for that button, active class set for it.
and for your main section you can fetch data in useEffect hook.
I think it is good to separate data and UI but for buttons what I say is good.
and you can store data in redux for your main section.

Navigate to a specific component (React)

I have a page 1 and a page 2. On page 1 is a specific component. On page 2 I have a button. After clicking on that button I want to navigate to the position of the specific component on page 1.
Is there a legit way to handle this?
By the way I am using GatsbyJS.
If you are using Gatsby, there is a plugin made for that :)
https://www.gatsbyjs.org/packages/gatsby-plugin-anchor-links/
Else you can just set an id on the component on page 2 and link with /page2#yourid

Dynamically create React Navigation version 3 navigators

I'm trying to create a multi-step form wizard using version 3 of React Navigation by following this tutorial. The tutorial describes dynamically creating a stack navigator using createStackNavigator(). This approach no longer works in version 3 of React Navigation and is listed in the docs as a Common Mistake. In version 3 of React Navigation createStackNavigator() should now be wrapped by createAppContainer() and an app should generally only have one app container.
How can I create a multi-step form wizard using React Navigation V3 that:
Receives an array of steps (React components)
Generates a progress bar
Generates a Next button on each screen and a Submit button on the last screen
Enables a way to save form state when navigating from one step to the next
Uses a stack navigator to navigate between the steps so displaying the default right to left transition animation
A example of the desired result is shown below:

Navigation Bar inside a dashboard:

I was wondering about what a better practice to add the nav side bar to my project, since its an angular2 im using components, so my dashboard has a main wrapper thats splits the content and and navbar itself.
both should be components.
now, when i want to navigate to other component, I can:
1. use a link to other component that holds the same navbar (duplicate code)
OR
2. change the html page to show another component (dynamic switching when click only for the content)
what do you think ? thanks!

Categories