我对React中的函数调用有疑问。我在一个onClick事件上有两个函数,它们在console.log中可以完美地工作,但是当我添加return时,它什么也不返回。这是代码
import React from "react";
let res;
let res2;
const Button = props => {
if (props.emptyTemplates !== undefined) {
res2 = props.emptyTemplates;
}
const myFunct = function() {
console.log(props.click);
};
const myFunct1 = function() {
if (props.class === "prod-button") {
console.log(res2);
}
};
return (
<button
onClick={event => {
myFunct(event);
myFunct1();
}}
className={props.class}
>
{/ {props.state ? "selected" : "select"} /}
select
</button>
);
};
export { Button };
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
我在做什么错?预先感谢。