in Education by
I'm using the React Native Elements Search Bar. Every time I call him, the dataSuccess function is called. When searching, only the searchLead function needs to work. I have read the React native elements search bar documentation. It still didn't work. I think I have a problem with my algorithm. I hope I can tell. Is there a better example of using a Search Bar? I share all the code with you. Thanks in advance for your help. export default class Lead extends Component { constructor (props) { super(props); this.state = { isLoading: true, isRefreshing: false, searchText: '', isSearch: false, offset: 0, maxSize: 10, leadList: [], searchData: [] }; } componentWillMount () { this.setState({ isLoading: true }); } componentDidMount () { this.loadData(); } handleRefresh = () => { this.setState({ offset: 0, maxSize: 10, isSearch: false, isRefreshing: true }, () => { this.loadData(); }); }; handleLoadMore = () => { this.setState({ maxSize: this.state.maxSize + 5 }, () => { this.loadData(); }); }; keyExtractor = (item, index) => index.toString(); loadData = async () => { try { const { offset, maxSize } = this.state; const username = await AsyncStorage.getItem('username'); const token = await AsyncStorage.getItem('token'); var credentials = Base64.btoa(username + ':' + token); var URL = `http://demo.espocrm.com/advanced/api/v1/Lead?sortBy=createdAt&asc&offset=${offset}&maxSize=${maxSize}`; axios.get(URL, { headers: { 'Espo-Authorization': credentials } }) .then(this.dataSuccess.bind(this)) .catch(this.dataFail.bind(this)); } catch (error) { Alert.alert( 'Hata', 'Bir hata meydana geldi. Lütfen yöneticiye başvurunuz.', [ { text: 'Tamam', onPress: () => null } ] ); } }; searchLead = async (text) => { try { if (text) { this.setState({ searchText: text, isSearch: true, isLoading: true }); const { searchText, maxSize } = this.state; const username = await AsyncStorage.getItem('username'); const token = await AsyncStorage.getItem('token'); var credentials = Base64.btoa(username + ':' + token); var URL = `http://demo.espocrm.com/advanced/api/v1/Lead?select=name&orderBy=createdAt&order=desc&where[0][type]=textFilter&where[0][value]=${searchText}&maxSize=${maxSize}`; axios.get(URL, { headers: { 'Espo-Authorization': credentials } }) .then(this.dataSearch.bind(this)) .catch(this.dataFail.bind(this)); } } catch (error) { Alert.alert( 'Hata', 'Arama başarısız oldu. Lütfen yöneticiniz ile görüşün.', [ { text: 'Tamam', onPress: () => null } ] ); } } dataSuccess (response) { console.log('test'); this.setState({ isRefreshing: false, isLoading: false, leadList: response.data.list }); } dataSearch (response) { this.setState({ isRefreshing: false, isLoading: false, isSearch: true, searchData: response.data.list }); } dataFail (error) { this.setState({ isLoading: false }); Alert.alert( 'Hata', 'Beklenmedik bir hata oluştu', [ { text: 'Tamam', onPress: () => null } ] ); } render () { const { isLoading, isRefreshing, searchText, isSearch, leadList, searchData } = this.state; return ( { isLoading ? : isSearch ? } keyExtractor={this.keyExtractor} refreshing={isRefreshing} onRefresh={this.handleRefresh} onEndReached={this.handleLoadMore} onEndReachedThreshold={0.5} /> : } keyExtractor={this.keyExtractor} refreshing={isRefreshing} onRefresh={this.handleRefresh} onEndReached={this.handleLoadMore} onEndReachedThreshold={0.5} /> } ); } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
setState is an async function and if you want to use state variable just after you set it. You should use setState callback param function which will be fired after state updates. this.setState({ foo: 'bar' }, () => console.log(this.state.foo)) Take a look at code below this.setState({ searchText: text, isSearch: true, isLoading: true }, async () => { const { searchText, maxSize } = this.state; const username = await AsyncStorage.getItem('username'); const token = await AsyncStorage.getItem('token'); // ... });

Related questions

0 votes
    I'm using the React Native Elements Search Bar. Every time I call him, the dataSuccess function is called ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    There is a React Native application, I want to make a cyclomatic complexity analysis. Please, tell me what ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    There is a React Native application, I want to make a cyclomatic complexity analysis. Please, tell me what ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 19, 2022 in Education by JackTerrance
0 votes
    I have a mat-table with a component app-order-statuses on every row. the component calls the statuses ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    Which is the function used to call a function in every time duration? (a) callafter() (b) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    I am trying to redirect to another site then run code on it. function gotonewpage() { window.location. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    I am trying to redirect to another site then run code on it. function gotonewpage() { window.location. ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    Which of the following keyword is used by calling function to handle exception thrown by called function? (a) ... Handling of Java Select the correct answer from above options...
asked Mar 1, 2022 in Education by JackTerrance
0 votes
    Dataframes can be converted into a matrix by calling the following function data ______ (a) matr() (b) matrix ... of R Programming Select the correct answer from above options...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    First I'll explain my senario: I have a page in which users login or register. The login control ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    Can someone tell me how can I Call a function in a string with function name in python program? E.x. Let's ... to perform this task. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    The ____________ is activated automatically every time you edit a Repository object. A. Change request B. SAP architecture C. Transport Request D. Transport Organizer...
asked Feb 20, 2023 in Technology by JackTerrance
0 votes
    New bitcoins are released every time a transaction is verified. A. True B. False...
asked Nov 30, 2022 in Education by JackTerrance
0 votes
    I have minified all my js files using require, but require created a minified js file( main.min.js ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 18, 2022 in Education by JackTerrance
...