我有这个 Output 组件,它应该在从父组件获取道具时呈现。
我怎样才能做到这一点?现在,当我单击一个按钮但没有调用 getTranslate 函数时它会呈现。在调试器中,我可以看到该组件具有所需的道具,它只是不运行我的 getTranslate 函数
import React, { useState } from "react";
import Axios from "axios";
const Output = (props) => {
const [output, setOutput] = useState(null);
const [url, setUrl] = useState(null);
const getUrl = (language, text) => {
console.log("GetURL ran with: ", language, text);
let url = "";
switch (language) {
case "yoda":
url =
" https://api.funtranslations.com/translate/yoda.json?text=" + text;
break;
case "valyrian":
url =
"https://api.funtranslations.com/translate/valyrian.json?text=" +
text;
break;
case "sith":
url =
"https://api.funtranslations.com/translate/sith.json?text=" + text;
break;
case "shakespeare":
url =
"https://api.funtranslations.com/translate/shakespeare.json?text=" +
text;
break;
case "pirate":
url =
"https://api.funtranslations.com/translate/pirate.json?text=" + text;
break;
case "minion":
url =
"https://api.funtranslations.com/translate/minion.json?text=" + text;
break;
case "lolcat":
url =
"https://api.funtranslations.com/translate/lolcat.json?text=" + text;
break;
case "klingon":
url =
"https://api.funtranslations.com/translate/klingon.json?text=" + text;
break;
case "hacker":
url =
"https://api.funtranslations.com/translate/hacker.json?text=" + text;
break;
case "dothraki":
url =
"https://api.funtranslations.com/translate/dothraki.json?text=" +
text;
break;
default:
break;
}
setUrl(url);
};
12345678_0001
蝴蝶刀刀
陪伴而非守候
慕尼黑的夜晚无繁华
相关分类