ich diese kleine Komponente habe:Anruf andere Komponente Methode
import React from 'react';
const Footer = (props) => {
return (
<footer className="top">
<p>{props.items} items in your menu</p>
</footer>
)
}
const updateItems = (n) => {
this.props.items = this.props.items + n;
};
Footer.propTypes = {
items: React.PropTypes.string.isRequired
};
export default Footer;
Und von der Hauptkomponente:
// All irrelevant imports
import Footer from './Footer';
class App extends React.Component {
// All the irrelevant vars and methods
removeFish = (key) => {
const fishes = {...this.state.fishes};
fishes[key] = null;
this.setState({ fishes });
Footer.updateItems(-1); // <-- This is not updating the items count in the footer component
};
}
Mein Footer.updateItems scheint nicht den Wert zu aktualisieren, selbst, dass die Konsole feuert keine Fehler und die App entspricht
Welches wäre der richtige Weg?
'updateItems' sollte eine Methode der 'Footer'-Komponente sein und einen Wert im Footer-Zustand aktualisieren, keine Requisiten. – Andrew