{"id":2314,"date":"2022-02-17T18:37:46","date_gmt":"2022-02-17T17:37:46","guid":{"rendered":"https:\/\/ekiwi.de\/?p=2314"},"modified":"2022-02-17T18:37:46","modified_gmt":"2022-02-17T17:37:46","slug":"react-und-javascript-element-aus-state-array-entfernen","status":"publish","type":"post","link":"https:\/\/ekiwi.de\/index.php\/2314\/react-und-javascript-element-aus-state-array-entfernen\/","title":{"rendered":"React und JavaScript: Element aus State Array entfernen"},"content":{"rendered":"<p>React State-Arrays ver\u00e4ndern.<\/p>\n<p><!--more--><\/p>\n<p>Heute hatte ich das Problem, dass ich ein Array in einem State einer React-Komponente ver\u00e4ndern wollte. Direkt sollte man dies nicht zu, sondern \u00fcber die <code>setState<\/code>-Methode. Damit schied leider auch die &#8222;<code>array.splice<\/code>&#8220; Methode aus. <\/p>\n<p>Hier eine m\u00f6gliche L\u00f6sung:<\/p>\n<pre>this.setState({\r\n    dataItems: this.state.dataItems.filter((dataItem) =&gt; {\r\n        return dataItem.id !== id;\r\n    })\r\n});<\/pre>","protected":false},"excerpt":{"rendered":"<p>React State-Arrays ver\u00e4ndern.<\/p>\n","protected":false},"author":1,"featured_media":2260,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[15],"tags":[44,561],"class_list":["post-2314","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-javascript","tag-react"],"_links":{"self":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts\/2314","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/comments?post=2314"}],"version-history":[{"count":0,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/posts\/2314\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/media\/2260"}],"wp:attachment":[{"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/media?parent=2314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/categories?post=2314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ekiwi.de\/index.php\/wp-json\/wp\/v2\/tags?post=2314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}