I have the following code in angular and I wonder how easy it can be "converted" to react. Here is what I am doing in angular
var app = angular.module('app',[]);
app.directive('myPlugin', function($compile) {
return {
restrict: 'AE',
link: function(scope, element) {
// Data loaded dynamically from db
var plugin_templ = '<h1>Hello {{who}}</h1>';
var plugin_script = 'scope.who = "world"';
eval(plugin_script);
var compiled = $compile(plugin_templ)(scope);
element.append(compiled);
}
}
})
Basically I load template and code from the database and compile it on the fly. Is there a similar way to do this in react ?
p.s. I am well aware how "dangerous" it can be and that I shouldn't use eval etc. However, it is done so.