Skip to content

Instantly share code, notes, and snippets.

@klzns
Created July 11, 2018 20:25
Show Gist options
  • Save klzns/2b913a19b3965c38a1b4f485854878d3 to your computer and use it in GitHub Desktop.
Save klzns/2b913a19b3965c38a1b4f485854878d3 to your computer and use it in GitHub Desktop.
React dentro de AngularJS
<react component="vtex.Hello" props=something.insideAngularScope"></react>
angular.module('vtex.react', [])
.directive 'react', ($translate) ->
restrict: 'E'
scope: {
component: '@',
props: '=',
},
link: (scope, elem, attrs) ->
componentPath = scope.component.split('.')
component = componentPath.reduce(((component, path) -> component[path]), window)
container = elem[0]
ReactDOM.render(
React.createElement(component, scope.props),
container
)
elem.on '$destroy', () ->
ReactDOM.unmountComponentAtNode(container)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment