Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

new_signup.js 1.4 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  1. import React, { useState } from 'react';
  2. const FormStepper = () => {
  3. const [currentStep, setCurrentStep] = useState(0);
  4. const [formData, setFormData] = useState({});
  5. const steps = [
  6. <div key="step1" className={currentStep === 0 ? 'step active' : 'step'}>Step 1 Content</div>,
  7. <div key="step2" className={currentStep === 1 ? 'step active' : 'step'}>Step 2 Content</div>,
  8. <div key="step3" className={currentStep === 2 ? 'step active' : 'step'}>Step 3 Content</div>,
  9. ];
  10. const handleNext = () => {
  11. if (currentStep < steps.length - 1) {
  12. setCurrentStep(currentStep + 1);
  13. }
  14. };
  15. const handlePrev = () => {
  16. if (currentStep > 0) {
  17. setCurrentStep(currentStep - 1);
  18. }
  19. };
  20. const handleSubmit = (e) => {
  21. e.preventDefault();
  22. console.log(formData);
  23. setFormData({});
  24. };
  25. const handleInputChange = (e) => {
  26. const { name, value } = e.target;
  27. setFormData({
  28. ...formData,
  29. [name]: value,
  30. });
  31. };
  32. return (
  33. <form onSubmit={handleSubmit}>
  34. {steps}
  35. <div>
  36. <button type="button" onClick={handlePrev} disabled={currentStep === 0}>Previous</button>
  37. <button type="button" onClick={handleNext} disabled={currentStep === steps.length - 1}>Next</button>
  38. </div>
  39. <div>
  40. <button type="submit">Submit</button>
  41. </div>
  42. <input type="text" name="exampleField" onChange={handleInputChange} />
  43. </form>
  44. );
  45. };
  46. export default FormStepper;
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...