생성 단추를 누를 때 임의의 활동을 생성 할 수있는 ReactJS 프로젝트에서 작업 중입니다. 내 API에서 가져 와서 일부 데이터를 표시하고 있습니다. 이것은 잘 작동합니다. 이제 가져 오기 작업을 수행하고 집계 구성 요소에있는 생성 버튼을 클릭 할 때마다 반환 된 데이터를 표시하려고합니다. 생성 버튼은 새로운 가져 오기를 수행하고 구성 요소를 새로 고쳐야합니다. 또한 기본적으로 비어 있어야합니다. 나는 잠시 동안 수색하고 관련 답변을 찾을 수 없습니다. 너희 중 몇 명이 나를 도울 수 있니? 감사.ReactJS 표시 가져 오기 응답 onClick
구성 요소
import React from 'react'
export class ItemLister extends React.Component {
constructor() {
super();
this.state={suggestion:""}
}
componentDidMount(){
fetch("......./suggestions/random", {
method: "GET",
dataType: "JSON",
headers: {
"Content-Type": "application/json; charset=utf-8",
}
})
.then((resp) => {
return resp.json()
})
.then((data) => {
this.setState({ suggestion: data.suggestion })
})
.catch((error) => {
console.log(error, "catch the hoop")
})
}
render() {
return(
<h2>
{this.state.suggestion}
</h2>
)
}
}
내가 제대로 이해하면 내가 아주 확실하지 ...하지만 당신이 당신을 추가하는 오전부터
import React from 'react'
import {ItemLister} from './apiCall'
export class Home extends React.Component {
constructor(props) {
super(props)
console.log()
window.sessionStorage.setItem ('name',this.props.params.name)
window.sessionStorage.setItem ('token', this.props.params.token)
}
render() {
return (
<div className="contentContainer AD">
<table>
<thead>
<tr>
<th><p>Het is heel leuk als het werkt!</p></th>
</tr>
</thead>
<tbody >
<tr><td><ItemLister/></td></tr>
</tbody>
</table>
<div className="container center">
<button>GENERATE</button>
<button>SAVE</button>
<button>MATCH</button>
</div>
</div>
)
}
}
같은이 기능 컴포넌트가 여전히 문제에 직면 할 수있다 렌더링 제안이 있습니까? –
렌더링 할 수 없습니다. 주요 문제는 생성 버튼에 onClick을 설정하여 가져 오기 기능을 연결하는 것입니다. –
생성 버튼을 클릭 할 때마다 ItemListener 구성 요소를 새로 고침하고 싶습니다. 옳은? –