1

I'm creating a very simply input form in my react-redux app with redux-form. I'm following along the with the example of the redux-form page, but it's throwing me an error. The source of the error comes from trying to set the component prop to React.DOM.input. It throws this error:

TypeError: _react2.default.DOM is undefined

However, if I pass the string 'input' into the component prop, it works fine, and I can see the changed state in my redux dev tool. I'm just reaaaaally not sure where I got the idea to put it as a string and now I'm super curious 😂.

let SubsForm = ({ handleSubmit, availScripts }) => {
    const subs = availScripts.map(script =>
        [
            <label htmlFor={script}>{script}</label>,
            <Field key={script} component={React.DOM.input} type="checkbox" name={script} />,
            <br />,            
        ]
    );

    return [
        <form>
            {subs}
        </form>
    ];
};

Thanks

2 Answers 2

2

There's a difference between import ReactDOM from "react-dom", and React.DOM.

The "react-dom" package is what you need to render React components into an HTML page.

Meanwhile, React.DOM was a set of factory functions for creating virtual DOM elements in render methods. It's been moved out into a separate react-dom-factories package, and is no longer part of the main React package as of React 16.

React.createElement() takes either a React component type or a string DOM HTML element name as its first argument, . The React.DOM factory functions wrapped up that process a bit. So, these are identical:

React.createElement("input", {name : "myInput"});
React.DOM.input({name : "myInput"})
Sign up to request clarification or add additional context in comments.

Comments

0

Try importing the react component.

 import React from "react";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.