You can send the function as props to your Header component. To do this, in the construction of your file "Main", you can bind the function you want to use.
In the example below, the "Main" component sends the "delete" function to the "Delete" component".
import {Container} from "./styles.js";
import Excluir from "../../components/Excluir/index";
export default class Main extends Component {
constructor(props) {
super(props);
this.deletar = this.deletar.bind(this);
}
deletar = async id => {
try {
//Executar comandos
} catch (error) {
//Em caso de erro
}
};
render() {
return (
<Container>
<Excluir
deletar={this.deletar}
codigo={1}
/>
</Container>
);
}
}
In your "Delete" component, you could use the function created in "Main" in this way:
import {Container, RemoveButton, Title, Subtitle, TextButton} from "./styles.js";
const Excluir = ({deletar, codigo }) => (
<Container>
<Title>Remover</Title>
<Subtitle>Tem certeza que deseja excluir?</Subtitle>
<RemoveButton onPress={() => deletar(codigo)}><TextButton>Sim</TextButton></RemoveButton>
</Container>
);
Blz! Thank you, it was very clear!
– Joel Germano