I've been building an application in my spare time, its backend is C# and I use Knockout js for the front end, to be honest its an app I use out side of my main job for learning purposes etc, I may launch it one day not really sure. I've now a new job where they use React, so my question is can I now integrate React into my app so I can begin learning this library? I'd aim to keep each component separate but does anyone think this a bad idea mixing libraries like this? I haven't learnt React yet hence I want to start integrating it into my side project though I don't really want to start rewriting all the Knockout JavaScript again also.
CodePudding user response:
A React app can be initialized on any DOM node you want. Pick a page you want to put React on, create a DOM node (a simple div
) and create a Element on that node.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
<title>Hello World</title>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
function App() {
return <h1>Hello, world!</h1>
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
</script>
</body>
</html>