I currently have a sidebar, and a page (home.component.js) to the right of this sidebar.
To make the content not fall behind the sidebar, I have included a padding left of 20vw in the body of my index.css
background: #f0f0f0 !important;
min-height: 100vh;
display: flex;
font-weight: 400;
font-family: 'Inter';
padding-left: 20vw;
}
However, this is casing the same padding to appear on my sign up form, featured below
Code for sign-up page is below
import React, { Component } from "react";
import { BrowserRouter } from "react-router-dom";
import TopNav from "./TopNav"
export default class SignUp extends Component {
render() {
return (
<navbar>
<TopNav />
</navbar>,
<div className="auth-wrapper">
<div className="auth-inner">
<form>
<h4>Sign Up</h4>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever
</p>
<div className="form-group">
<label>First name</label>
<input type="text" className="form-control" placeholder="First name" />
</div>
<div className="form-group">
<label>Last name</label>
<input type="text" className="form-control" placeholder="Last name" />
</div>
<div className="form-group">
<label>Email address</label>
<input type="email" className="form-control" placeholder="Enter email" />
</div>
<div className="form-group">
<label>Password</label>
<input type="password" className="form-control" placeholder="Enter password" />
</div>
<p classname="forgot-password text-right">
Already registered log in?
</p>
<button type="submit" className="button">Sign Up</button>
</form>
</div>
</div>
);
}
}
How can I make this padding only appear on my homepage, and not carry forward to my Sign Up page, so the sign up page has no padding-left?
Homepage
render() {
return (
<div style={{ display: "flex" }}>
<Sidebar />
<h1>Right of sidebar page </h1>
</div>
);
}
}
Related
This question already has an answer here:
Uncaught TypeError: Cannot read properties of undefined (reading 'pathname') and The above error occurred in the <Link> component:
(1 answer)
Closed 6 months ago.
when I add Link tag in the component Login the page content disappears, what might be the problem?
Login.js (without Link tag):
import React from 'react'
import { Link } from 'react-router-dom'
function Login() {
return (
<div className='container mx-auto'>
<form className='col-md-5 mx-auto'>
<h2 className='m-5'>Login into MERN Project</h2>
<div className="mb-3">
<label for="exampleInputEmail1" className="form-label">Email address</label>
<input type="email" className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" required/>
<div id="emailHelp" className="form-text">We'll never share your email with anyone else.</div>
</div>
<div className="mb-3">
<label for="exampleInputPassword1" className="form-label">Password</label>
<input type="password" className="form-control" id="exampleInputPassword1" required/>
</div>
<button type="submit" className="btn btn-primary">Submit</button>
</form>
<nav>
</nav>
</div>
)
}
export default Login
Output:
enter image description here
Login.js with Link tag:
import React from 'react'
import { Link } from 'react-router-dom'
function Login() {
return (
<div className='container mx-auto'>
<form className='col-md-5 mx-auto'>
<h2 className='m-5'>Login into MERN Project</h2>
<div className="mb-3">
<label for="exampleInputEmail1" className="form-label">Email address</label>
<input type="email" className="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" required/>
<div id="emailHelp" className="form-text">We'll never share your email with anyone else.</div>
</div>
<div className="mb-3">
<label for="exampleInputPassword1" className="form-label">Password</label>
<input type="password" className="form-control" id="exampleInputPassword1" required/>
</div>
<button type="submit" className="btn btn-primary">Submit</button>
</form>
<nav>
<Link className=''>Not a member? Register here</Link>
</nav>
</div>
)
}
export default Login
The output is empty page:
enter image description here
In Link Component add link destination..
<Link to="/register" > Not a member? Register here</Link>
Hi I am working on a React project in my project one button is coming soo many times. So I created one component for Button and I am reusing that component where ever I get a button. Now the problem is when I am trying to apply onClick function to that Button component, my function is not working so please help me to resolve this issue.
This is Button Component Button.js
import React from "react";
import "./Button.css";
const Button = () => {
return (
<div>
<button className="btn btn-primary">Show login button</button>
</div>
);
};
export default Button;
This is Button.css, I have written nothing in this
This is App.js
import React, { useState } from "react";
import Button from "./Button/Button";
import "./App.css";
const App = () => {
const [hideForm, setHideForm] = useState(false);
const showLoginForm = () => {
setHideForm(true);
};
return (
<div className="container">
<div className="row justify-content-center">
<div className="col-4">
{hideForm ? (
<div className="loginform">
<form>
<div className="form-group">
<label htmlFor="email">Email</label>
<input
type="email"
className="form-control"
id="email"
placeholder="Enter email"
></input>
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input
type="password"
className="form-control"
id="password"
placeholder="Enter password"
></input>
</div>
<button type="submit" className="btn btn-primary mt-3">
Submit
</button>
</form>
</div>
) : (
<div className="signupform">
<form>
<div className="form-group">
<label htmlFor="firstname">Firstname</label>
<input
type="text"
className="form-control"
id="firstname"
placeholder="Enter firstname"
></input>
</div>
<div className="form-group">
<label htmlFor="lastname">Lastname</label>
<input
type="text"
className="form-control"
id="lastname"
placeholder="Enter lastname"
></input>
</div>
<div className="form-group">
<label htmlFor="email">Email</label>
<input
type="email"
className="form-control"
id="email"
placeholder="Enter email"
></input>
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input
type="password"
className="form-control"
id="password"
placeholder="Enter password"
></input>
</div>
<button type="submit" className="btn btn-primary mt-3">
Submit
</button>
</form>
</div>
)}
<div className="buttons mt-3">
<Button onClick={() => showLoginForm()}></Button>
</div>
</div>
</div>
</div>
);
};
export default App;
const Button = ({handleClick}) => {
return (
<div>
<button onClick={handleClick} className='btn btn-primary'>Show login button</button>
</div>
)
}
Use It like this:
<Button handleClick={()=>anyFunc()}/>
or
<Button handleclick={anyFunc}/>
``
You can pass the Parent's on click event to child as a props and when you click on the child component's button event that is being declared on the parent's component can be called. Here is how you can do it:
Code on the Parent Component:
const myClick =()=>{
// on click will be called here when button will be pressed
}
<Button onClick={this.myClick}></Button>
Code on the Child Component:
<button onClick={this.props.myClick}>Click Here</button>
Please help me resove the errors in the following code. I have tried several times but top avail.
import React from "react";
export class Login extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div className="base-container">
<div className="header">Login</div>
<div className="content"></div>
<div className="form">
<div className="form-group">
<label htmlFor="username">Username</label>
<input type="text" name="username" placeholder="username" />
</div>
<div className="form-group">
<label htmlFor="password">Password</label>
<input type="password" name="password" placeholder="password" />
</div>
</div>
<div className='footer'>
<button type="button" className="btn">
Login
</button>
</div>
);
}
}
error:
Unexpected token. Did you mean `{'{'` or `&brace;`?
enter image description here
your footer div is not closed. Please close that </div>
import React , { Component } from 'react'
class Login extends Component{
constructor(props){
super(props)
}
render(){
return(
<form className="login-form">
<h1>login</h1>
<div>
<div className="form-group">
<label for="name">
Name :
</label>
<input name="name" type="text" value="" placeholder="Your Name" />
</div>
<div className="form-group">
<label for="password">
Password :
</label>
<input name="password" type="Password" value="" placeholder="Password" />
</div>
<input type="submit">Submit</input>
</div>
</form>
)
}
}
export default Login
I think the issue is here,
//input is an empty tag and you have provided Submit as children here
<input type="submit">Submit</input>
It should be simply this,
<input type="submit" value="Submit" />
ravibagul91's answer is correct. input is self-closing element. You cannot have children in it.
Alternatively, you may use button:
<button type="submit">Submit</button>
To this:
<input type="submit" value="Submit" />
I kinda getting lost here while i try to populate a redux-form V6.
I'm trying to create a contact form with person and company details. Since I'm new to the react universe I jump from one Doc/Tutorial to the other... So it may looks a bit scraped together.
I don't understand the concept how I can tell the Form that it has
to submit a ID that is comming from "props.match.params.id".? Or is
it just a bind and will get the result when i call this.props.dispatch(getContact(this.props.match.params.id)); in the Contact Component?
The reducer returns a Object that has the Person and Company as
"sub"-Object how can i match that to the Form?
Is there a way to debug the Form? I just see that my request returned a contact but i don't know if it even reaches the Form.
I use react-router to link to:
/contacts/contact/:id -> Populated Contact Form
Because of the redux/routerv4 issues i have to wrap my React.Component in withRouter to get the params in props. I don't know how i can connect withRouter and mapDispatchToProps, So my Contact Component looks as follows:
import React from 'react';
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { FormattedMessage } from 'react-intl';
import {getContact} from "../../../Actions/contactsActions";
import ContactForm from './Forms/ContactForm';
#connect((store) => {
return {
contacts: store.contacts,
countries: store.countries,
contactCategories: store.contactCategories
}
})
class Contact extends React.Component {
constructor(props) {
super(props);
this.state = {
errors: {},
};
}
componentWillMount() {
if(this.props.match.params.id) {
this.props.dispatch(getContact(this.props.match.params.id));
}
}
handleSubmit(data) {
console.log(data);
}
render() {
return (
<div className="contact-container">
<ContactForm onSubmit={this.handleSubmit} />
</div>
)
}
}
export default withRouter(Contact);
And the Form looks like:
import React from 'react'
import { connect } from 'react-redux'
import { Field, reduxForm, formValueSelector } from 'redux-form'
import { FormattedMessage } from 'react-intl';
import {getContact} from "../../../../Actions/contactsActions";
class ContactForm extends React.Component {
render() {
const { handleSubmit } = this.props;
return (
<form onSubmit={handleSubmit}>
<div className="tab-pane fade show active" id="general" role="tabpanel" aria-labelledby="general-tab">
<div className="row">
<div className="col-lg-6 col-6">
<h2>
<FormattedMessage id={ 'Company' } values={{name:"Company"}} />
</h2>
<div className="form-group row">
<label htmlFor="company-name" className="col-4 col-form-label">
<FormattedMessage id={ 'Companyname' } values={{name:"Company name"}} />
</label>
<div className="col-8">
<Field component="input" className="form-control" name="company-name" placeholder="Company name" />
</div>
</div>
<div className="form-group row">
<label htmlFor="other-name" className="col-4 col-form-label">
<FormattedMessage id={ 'Othername' } values={{name:"Other name"}} />
</label>
<div className="col-8">
<Field component="input" className="form-control" name="other-name" placeholder="In case of sister company/group"/>
</div>
</div>
</div>
<div className="col-lg-6 col-6">
<h2>
<FormattedMessage id={ 'Person ' } values={{name:"Person"}} />
</h2>
<div className="form-group row">
<label htmlFor="person-language" className="col-4 col-form-label">
<FormattedMessage id={ 'Language' } values={{name:"Language"}} />
</label>
<div className="col-8">
<Field component="select" className="form-control" name="person-language" />
</div>
</div>
<div className="form-group row">
<label htmlFor="person-gender" className="col-4 col-form-label">
<FormattedMessage id={ 'Gender' } values={{name:"Gender"}} />
</label>
<div className="col-8">
<Field component="select" className="form-control" name="person-gender">
</Field>
</div>
</div>
<div className="form-group row">
<label htmlFor="person-salutation" className="col-4 col-form-label">
<FormattedMessage id={ 'Salutation' } values={{name:"Salutation"}} />
</label>
<div className="col-8">
<Field component="select" className="form-control" name="person-salutation" />
</div>
</div>
<div className="form-group row">
<label htmlFor="person-title" className="col-4 col-form-label">
<FormattedMessage id={ 'Title' } values={{name:"Title"}} />
</label>
<div className="col-8">
<Field component="input" className="form-control" name="person-title" placeholder="Prof. Dr. Dr."/>
</div>
</div>
<div className="form-group row">
<label htmlFor="first-name" className="col-4 col-form-label">
<FormattedMessage id={ 'First-name' } values={{name:"First name"}} />
</label>
<div className="col-8">
<Field component="input" className="form-control" name="first-name" placeholder="First name"/>
</div>
</div>
<div className="form-group row">
<label htmlFor="further-names" className="col-4 col-form-label">
<FormattedMessage id={ 'Further-names' } values={{name:"Further names"}} />
</label>
<div className="col-8">
<Field component="input" className="form-control" name="further-names" placeholder="Further names"/>
</div>
</div>
<div className="form-group row">
<label htmlFor="last-name" className="col-4 col-form-label">
<FormattedMessage id={ 'Last-name' } values={{name:"Last name"}} />
</label>
<div className="col-8">
<Field component="input" className="form-control" name="last-name" placeholder="Last name"/>
</div>
</div>
<div className="form-group row">
<label htmlFor="job-title" className="col-4 col-form-label">
<FormattedMessage id={ 'Job-title' } values={{name:"Job title"}} />
</label>
<div className="col-8">
<Field component="input" className="form-control" name="job-title" placeholder="Last name"/>
</div>
</div>
</div>
</div>
</div>
</form>
)
}
}
const validate = (values) => {
const errors = {};
if(!values.Companyname) {
errors.Companyname = "Enter a Companyname";
}
return errors;
};
ContactForm = reduxForm({
validate,
form: 'contact',
enableReinitialize : true
})(ContactForm);
ContactForm = connect(
state => ({
initialValues: state.contacts.contacts
}),
{ load: getContact }
)(ContactForm);
export default ContactForm;