Answer the question
In order to leave comments, you need to log in
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>
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.
Answer the question
In order to leave comments, you need to log in
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
In React 16, React.createClass is no longer supported. Use ES6 classes
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question