G
G
Gagatyn2018-11-18 10:19:34
React
Gagatyn, 2018-11-18 10:19:34

Why is React.createClass not a function?

Hello!
I do everything for beginners .
When creating a component using React.createClass(), the console throws an error React.createClass is not a function
The code itself

<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>

<script type="text/babel">
        const my_news = [{
                author: 'Lorem',
                text: 'Lorem ipsi!'
            }, {
                author: 'IPSUM',
                text: 'Lorem initi nobis aspernatur sed,'
            }, {
                author: 'DOLLAR',
                text: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Molestias id, venia'}
        ];

       let News = React.createClass({ // <---- ERROR
          render: function() {
            return (
              <div className="news">новости!</div>
            );
          }
        });

        class Comments extends React.Component {
            render() {
                return <div className="comments comments--indend">Нет новостей - нечего комментировать!</div>
            }
        };

        const App = () => {
            return (
                <div className="app">
                    <div>Всем привет, я компонент App! Я умею отображать новости:</div>
                    <News/>
                    <Comments  data={my_news}/>
                </div>
            )
        };

        ReactDOM.render(
            <App/>,
            document.getElementById('main')
        );
    </script>

1. Tell me how to solve the problem with classes
Add. questions:
2. The Comments component does not see the data attribute, what should I do?
3. I can't move the component to a separate file (you have to write it in index.html). Gives an error message
Access to XMLHttpRequest at 'file:/.../react/js/script.jsx' from origin 'null' has been blocked by CORS policy: 
Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

Tell me, please, what to do?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
adovnik, 2018-11-18
@Gagatyn

There is a new version of this tutorial https://maxfarseer.gitbooks.io/react-course-en-v2/... - where you won't run into this problem.
To make React.creatClass work for you, find a CDN with an older version of react. 15.4 seemed to work There is a
lot of information on the Internet about the CORS error. Here is an option from react site https://reactjs.org/docs/cross-origin-errors.html

N
Nikita Pogadaev, 2018-11-18
@laight

In React 16, React.createClass is no longer supported. Use ES6 classes

A
Anton Filippov, 2018-11-18
@vicodin

do not study outdated courses

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question