There are two files: RegistrationScreen.js and api.js.
Inside api.js I'm running fetch()
function:
export const fetchAllUsers = () => { fetch(`http://${localIP}:${port}/api/userData`) .then(res => res.json()) /* .then(json => console.warn('JSON: '+ json.userData[0].username)) .catch(e => console.warn('ERROR: '+ e)) */}
If comment back the second .then()
I'm able to see username from response.
I'm importing this function into RegistrationScreen.js:
import { fetchAllUsers } from '../../constants/api';export default class RegistrationScreen extends Component{ static defaultProps = { fetchAllUsers } onCreateButtonPress = async () => { ... let usernameValidation = await this.checkUsernameUniqueness(); ... } checkUsernameUniqueness = async () => { const data = await this.props.fetchAllUsers(); console.warn('user = '+ data) } ...}
And as an outcome I get in the console user = undefined.Why I can see the data inside api.js but not in RegistrationScreen.js?
UPDATE_1
If do console.warn(this.props.fetchAllUsers)
inside RegistrationScreen.js I see the function code so the function is visible.