React Native

typeScript ) μžμ‹μ—κ²Œ ν•¨μˆ˜ 전달.

Machine_μ›… 2022. 9. 19. 22:53
728x90
λ°˜μ‘ν˜•
interface ButtonProps {
  sum: (a: number, b: number) => number;
  logMessage: (message: string) => void;

  // πŸ‘‡οΈ turn off type checking
  doSomething: (params: any) => any;
}

function Container({sum, logMessage, doSomething}: ButtonProps) {
  console.log(sum(10, 15));

  logMessage('hello world');

  doSomething('abc');

  return <div>Hello world</div>;
}

const App = () => {
  const sum = (a: number, b: number) => {
    return a + b;
  };

  const logMessage = (message: string) => {
    console.log(message);
  };

  return (
    <div>
      <Container sum={sum} logMessage={logMessage} doSomething={logMessage} />
    </div>
  );
};

export default App;
728x90
λ°˜μ‘ν˜•