Skip to content

Instantly share code, notes, and snippets.

@erandirjunior
Created September 29, 2020 13:47
Show Gist options
  • Save erandirjunior/fb5efb3b27fa86ad3a2a93d7c17494f9 to your computer and use it in GitHub Desktop.
Save erandirjunior/fb5efb3b27fa86ad3a2a93d7c17494f9 to your computer and use it in GitHub Desktop.
import React, { useState, useEffect } from 'react';
import { Alert } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import api from '~/services/api';
import { useDispatch, useSelector } from 'react-redux';
import { storeRequest } from '~/store/modules/store/actions';
import ContainerMain from '~/components/ContainerMain';
// import {Text} from "~/components/Button/styles";
import { FlatList, Text, Button } from 'react-native';
const Store = () => {
const dispatch = useDispatch();
let stores = []
let names = []
const fetchData = async () => {
api.get("/establishments?name=&street&state=&city=")
.then(resp => {
stores = resp.data
alert('aqui')
})
}
useEffect(() => {
fetchData()
}, [dispatch, stores, names]);
return (
<ContainerMain>
{
stores.map((item, index) => (
<Text>
{item.name}
</Text>
))
}
<FlatList
data={names}
renderItem={({item}) => <Text>{item.key}</Text>}
/>
<Text>aqui</Text>
</ContainerMain>
);
};
Store.navigationOptions = () => ({
title: 'Lojas',
tabBarIcon: ({ color }) => <Icon name="store" size={28} color={color} />,
});
export default Store;
@IgorDePaula
Copy link

import React, { useState, useEffect } from 'react';
import { Alert } from 'react-native';
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
import api from '~/services/api';

import { useDispatch, useSelector } from 'react-redux';
import { storeRequest } from '~/store/modules/store/actions';

import ContainerMain from '~/components/ContainerMain';
// import {Text} from "~/components/Button/styles";
import { FlatList, Text, Button } from 'react-native';

const Store = () => {
  const dispatch = useDispatch();
  const [stores, setStore] = useState([])
  let names = []

  const fetchData = async () => {
    api.get("/establishments?name=&street&state=&city=")
      .then(resp => {
       setStore(resp.data)
        alert('aqui')
      })
  }

  useEffect(() => {
    fetchData()
  }, [dispatch, stores, names]);

  return (
    <ContainerMain>
      {
        stores.map((item, index) => (
            <Text>
              {item.name}
            </Text>
        ))
      }
      
      <FlatList
        data={stores}
        renderItem={({item}) => <Text>{item.key}</Text>}
      />
      <Text>aqui</Text>
    </ContainerMain>
  );
};
Store.navigationOptions = () => ({
  title: 'Lojas',
  tabBarIcon: ({ color }) => <Icon name="store" size={28} color={color} />,
});

export default Store;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment