example.js
import React from "react";
import { getInfo } from '../../actions/stuff'
class example extends React.Component {
state = {
}
constructor(props) {
super(props);
const values = getInfo("123")
}
stuff.js
export const getInfo = (id) => {
const url = `/profile/${id}`;
fetch(url)
.then(res => {
if (res.status === 200) {
return res.json();
}
})
.then(json => {
if (json) {
return json
}
})
.catch(error => {
console.log(error);
});
}
우편 배달부에서는 {firstName : something, lastName : something, age : something}에 대해 3 개의 값을 가진 json을 반환합니다. json을 반환하고 싶지만 "const values = getInfo ("123 ")"는 정의되지 않습니다. getInfo 함수에서 console.log (json)이면 원하는 값을 제공하므로 내가 뭘 잘못하고 있는지 알 수 없습니다.