xjpro / react-in-angularjs

A super simple way to render React components in AngularJS
The Unlicense
23 stars 13 forks source link

How to give functions as props #3

Closed Waltari10 closed 4 years ago

Waltari10 commented 4 years ago

Hey, love the package. It indeed is super simple. However I struggle to pass any functions to my React component.

import React from 'react';
import { angularize } from 'react-in-angularjs';

const ListItem = ({ myFunc }) => {

  return (
    <a
      onClick={myFunc}
      className="block small float-right"
    >
        Show
    </a>
  );
};

angularize(ListItem, 'listItem', angular.module('app.core'), {
  myFunc: '&',
});

And where i use it:

    <list-item 
        myFunc="listVm.myFunc"
    ></list-item>
   vm.myFunc = () => {
        console.log('triggered!');
  };

So how to get functions as props to work?

Waltari10 commented 4 years ago

Everytime I try give functions as props I forgot about angularJS retarded naming conventions.

So

<list-item 
  myFunc="listVm.myFunc"
></list-item>

To

<list-item 
  my-func="listVm.myFunc"
></list-item>

And it works!