Formik
I am new to formik and start using it every time i start learning i got this issue
Uncaught Error: Element type is invalid: expected a string (for
built-in components) or a class/function (for composite components)
but got: object.
I am unable to locate error cause this is my code
// here is Login.js file
import React, { Component } from "react";
import { Row, Col, Button } from "react-bootstrap";
import validator from "validator";
import { withFormik, Form, Field } from 'formik';
import Yup from 'yup';
import { RingLoader } from "react-spinners";
import "./Login.css";
import logo from "../../img/logo.png";
var NotificationSystem = require("react-notification-system");
class Login extends Component {
render() {
let { errors, touched } = this.props;
console.log("Login Component",this.props);
return (
<div className="content">
<Row>
<Col md={4} mdOffset={4} xs={10} xsOffset={1}>
<div style={stylelogobox}>
<img src={logo} style={logoStyle} />
</div>
<Form className="form-horizontal">
<fieldset>
<legend className="text-center">
<h2>Login</h2>
</legend>
<div className="form-group">
<label className="col-lg-2 control-label">Username</label>
<div className="col-lg-10">
<Field
type="text"
className="form-control"
placeholder="username"
name="username"
/>
{errors.username && touched.username && errors.username}
</div>
</div>
<div className="form-group">
<label htmlFor="inputPassword" className="col-lg-2 control-label">
Password
</label>
<div className="col-lg-10">
<Field
type="password"
className="form-control"
placeholder="Password"
name="password"
/>
{errors.password && touched.password && errors.password}
</div>
</div>
<div className="form-group">
<Col lg={10} lgOffset={2}>
<button
// disabled={this.props.user.isLogging}
className="btn btn-primary login-button btn-block LoginButton"
// disabled={this.state.isEnabled}
// onClick={this.handlesOnLogin}
>
<span> Login </span>
</button>
</Col>
</div>
</fieldset>
</Form>
</Col>
</Row>
<Row>
<Col md={4} mdOffset={4} xs={10} xsOffset={1}>
<div className="pull-right">
<Button bsStyle="default" onClick={this.goForgetPassword}>
Password Reset
</Button>
</div>
</Col>
</Row>
<div className="sweet-loading loadingSpinner">
<RingLoader
color={"#5c1a3e"}
//loading={this.state.loading}
loading={this.props.user.isLogging}
/>
</div>
<div>
<NotificationSystem ref="notificationSystem" />
</div>
</div>
);
}
const formikEnhancer = withFormik({
initialValues: { username: "", password: "" },
handleSubmit: (values, { setSubmitting }) => {
setTimeout(() => {
alert(JSON.stringify(values, null, 2));
setSubmitting(false);
}, 400);
}
});
export default formikEnhancer(Login);
I am importing this file to index.js where i am connecting this to redux store. index.js and login.js are in same folder
here is Index.js
import { connect } from "react-redux";
import Login from "./Login";
import {
login,
loginRequestLoader,
resetInvaliduser
} from "../../redux/actions/user";
const mapStateToProps = state => {
return {
user: state.user,
loginFlag: state.user.login
};
};
const mapDispatchToProps = dispatch => {
return {
loginRequestLoader: () => dispatch(loginRequestLoader()),
login: (username, password) => dispatch(login(username, password)),
resetInvaliduser: () => dispatch(resetInvaliduser())
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(Login);
here is Import from index.js file into Routes file
import Login from './views/login/index';
i don't know why this is getting the error i have tries withFormik and also Formik component but nothing work i also tries to see props in Login component using console log but it is also not logging the props means nothing is log.
Hello dude,
I suggest you to use withFormik, based on your code
It should be like this (I removed the unused code, just to make it clean):
https://gist.github.com/yuritoledo/86866216175f0ef43fc2bfb3db1da96f
I have also use that approach but the result are same
I tested it on a codesandbox, and it worked. I have nt this code anymore. Could you create one, with your code?
I recently updated [email protected] and ran into this issue as well:
Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
Which version of react-dom are you using? From my tests with react@16, it looks like any version below [email protected] will show this error. I haven't yet identified the specific cause of this error, since it's a generic catch-all for various import errors.
This CodeSandbox demonstrates the error: https://codesandbox.io/s/0vrn83o6ww
(Change the react/react-dom versions to test your environment)
If you're using react@16, update react-dom and this should fix the error.
Thanks @jaredpalmer et al. for all your work with this great project!
Getting the same error, even using [email protected] and [email protected]. The React Native sample triggers the error as well.
react@^16.2.0
react-native@^0.53.3
Hi, I have a similar problem...
Also upgrading react-dom to the latest version didn't help...
Still seeing this error with [email protected].
Most helpful comment
I recently updated
[email protected]and ran into this issue as well:Which version of
react-domare you using? From my tests withreact@16, it looks like any version below[email protected]will show this error. I haven't yet identified the specific cause of this error, since it's a generic catch-all for various import errors.This CodeSandbox demonstrates the error: https://codesandbox.io/s/0vrn83o6ww
(Change the react/react-dom versions to test your environment)
If you're using
react@16, updatereact-domand this should fix the error.Thanks @jaredpalmer et al. for all your work with this great project!