0

그래서 react-native-router-flux가 포함 된 ignite CLI를 사용하고 있습니다.교체, 재설정 및 새로 고침이있는 반응식 기본 라우터 광속 새로 고침 구성 요소

내 질문에, 나는 사용자 프레스 '적용'은 여기에 코드

<TouchableOpacity style={styles.button} onPress={this.onApply.bind(this)}> <Text style={styles.buttonText}>Apply</Text> </TouchableOpacity>

async onApply(){ 

var token = await AsyncStorage.getItem(STORAGE_KEY) 
var url = "http://purwadhikaconnect.southeastasia.cloudapp.azure.com/api/applicants" 
var jobId = this.props.jobData.Id 
console.log('int?', jobId); 
var config = { 
    method: "POST", 
    headers:{ 
    'Content-Type' : 'application/json', 
    'Accept' : 'application/json', 
    "Authorization" : 'Bearer ' + token 
    }, 
    body: JSON.stringify({ 
    JobId : parseInt(jobId) 
    }) 
} 

return fetch(url, config).then((response) => response.json()) 
.then(this.setState({ 
    isApplied: true, 
})).then((response) =>{Alert.alert('Job Applied Successfully')}) 
.then(this.setState({currentApplicant: this.state.currentApplicant + 1})) //trying to manipulate the value 
.then(NavigationActions.Jobs({type: 'reset'})) 
.catch((exception) => {Alert.alert('You have applied for this job!')}) 

}

때 데이터베이스에 업로드됩니다 소품에서 데이터를 데있다

이제 데이터가 성공적으로 업로드되지만 자동으로 새로 고침되지는 않습니다. shouldComponentUpdate() 과 같은 구성 요소 업데이트주기를 사용하고 있습니다. 내 액션 유형이 reset 인 것을 확인할 수 있습니다. 이제 Actionconst.replace을 사용하는 경우 내 메뉴 버튼이 뒤로 버튼으로 바뀝니다. 그리고 내가 ActionConst.refresh()을 사용하면 새로 고침도되지 않습니다. 제가 몇 달 동안이 문제를 해결해 봤지만 해결할 거의 모든 것을 시도했지만 실망스럽지 않았습니다 ... (

답변

1

저는 여러분이 setStates

.then((response) => this.setState({ isApplied: true })) 
+0

새로운 통찰력을 주셔서 감사합니다. 수정 된 데이터를 수정하여 (응답) 웹 사이트에 포함시킬 수 있습니다. '하지만 좋은 연습입니까 아니면 더 좋은 해결책입니까? –

+0

표준 연습이 있다고는 생각하지 않지만 게시 요청에 대한 데이터를 반환하고 싶습니다. –