I have been trying to get the Flux Todo List Tutorial running in an MVC project using ReactJS.Net.
I am using Gulp and Browserify to bundle files and then making a call to render the React component in my view. Relevant part of gulpfile.js:
gulp.task('build', function(){
browserify({
entries: [path.ENTRY_POINT],
transform: [reactify]
})
.bundle()
.pipe(source(path.NON_MINIFIED_OUT))
.pipe(gulp.dest(path.DEST_BUILD));
});
I have changed the App.js file to define my component globally:
global.React = require('react');
global.TodoApp = require('./components/TodoApp.react');
And am trying to use in my view like so:
<div id="app">
@Html.React("TodoApp", new {})
</div>
<script src="http://fb.me/react-0.13.3.min.js"></script>
@Scripts.Render("~/bundles/reactApp")
@Html.ReactInitJavaScript()
But it throws the following error at run time:
Could not find a component named 'TodoApp'. Did you forget to add it to App_Start\ReactConfig.cs?
I have added the output from Browserify to my ReactConfig.cs:
public static void Configure()
{
ReactSiteConfiguration.Configuration
.AddScript("~/dist/build.js"); // Have also tried .AddScriptWithoutTransform
}
But it doesn't seem to help.
It works fine if I just render on client side:
<div id="app">
</div>
@Scripts.Render("~/bundles/reactApp")
<script>
React.render(
React.createElement(TodoApp, null),
document.getElementById('app')
);
</script>