Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Hussein Zaki
@Hussein90
okay
Brad
@bradtaniguchi
@cmccormack you still around to help @Hussein90 ?
Christopher McCormack
@cmccormack
working atm
I know the answer and have pointed directly at it @Hussein90 you need to put some logs in and try to figure out what you're changing that is breaking it
Take your current function and at least try to log something...
  deletePost = (index, e) => {
    const dataposts = Object.assign([], this.state.data.posts);
    dataposts.splice(index, 1);
    this.setState({ data: dataposts }, () => console.log(this.state.data));
  };
above I added a log statement that will run when setState has completed
try that, then try to determine why your code will fail after running the deletePost method
Hussein Zaki
@Hussein90
now in console.log it changed to an object and still disappear all
Brad
@bradtaniguchi
What is in the object, since that's the state of the app
Hussein Zaki
@Hussein90
getting the info of the first post
in arry like
{title: "CopyRight Automatico", tags: "[JS]", id: 1, userId: 1, name: "Shopping", …
Christopher McCormack
@cmccormack
yup, and what was data prior to that?
  deletePost = (index, e) => {
    console.log(this.state.data) // <= Add this log
    const dataposts = Object.assign([], this.state.data.posts);
    dataposts.splice(index, 1);
    this.setState({ data: dataposts }, () => console.log(this.state.data));
  };
Hussein Zaki
@Hussein90
now when i click on for example one the first button the info of the second appear and vise versa also the same
on console
Christopher McCormack
@cmccormack
@Hussein90 I have no idea what you mean, can you show us?
Hussein Zaki
@Hussein90
Opera Snapshot_2018-10-23_002142_localhost.png
the red arrrow for the first button info up of it and other arrow for the second button and info up of it also
here is the console appear after i click on the first button
2018-10-23_0-23-42.jpg
@cmccormack
Hussein Zaki
@Hussein90
you can check it by yourself at
https://codesandbox.io/s/wy34yom6nl
Christopher McCormack
@cmccormack
@Hussein90 notice how the first log statement (above undefined) is an object, and the second log statement (below undefined) is an array?
Hussein Zaki
@Hussein90
yes
Christopher McCormack
@cmccormack
@Hussein90 Should it?
Hussein Zaki
@Hussein90
no
i think
Christopher McCormack
@cmccormack
No, it should not, it should have the same structure. You are overriding data with your posts array, but data should contain a posts property and a categories property, correct?
Hussein Zaki
@Hussein90
correct
but i want for every property it's individual delete button
Christopher McCormack
@cmccormack
Right...
You are overwriting your entire data object with an array, that's why it isn't working.
you aren't deleting any single item, you're completely destroying your state structure
Hussein Zaki
@Hussein90
when i am click on delete i destroy the whole app
Christopher McCormack
@cmccormack
You are turning state: { data: { posts: [...], categories: [...] } } into state: { data: [...] }
That's the best I'm going to be able to do to help right now @Hussein90 , I have to go for a while.
Hussein Zaki
@Hussein90

now it get

@Hussein90 notice how the first log statement (above undefined) is an object, and the second log statement (below undefined) is an array?
it returns now is null

this.setState({  data: { posts: [], categories: [] } }, () => console.log(this.state.data));
Hussein Zaki
@Hussein90
anyone here help me to finish this please
Brad
@bradtaniguchi
@Hussein90 sounds like you already figured it out?
Hussein Zaki
@Hussein90
still not working
still all disappear
Brad
@bradtaniguchi
@Hussein90 Have you inspected the html to see what actually is left? (hint: there is stuff there)
Using your dev tools, to see what is left over in the view
it's actually really obvious once you see what is currently there after you hit delete
Hussein Zaki
@Hussein90
@bradtaniguchi these appear
{posts: Array(0), categories: Array(0)}////
Brad
@bradtaniguchi
yea... so if your posts and categories are empty what do you render to the use according to the react code you currently hav?
Hussein Zaki
@Hussein90
they are not empty at all
Brad
@bradtaniguchi
whats not empty?
Hussein Zaki
@Hussein90
Opera Snapshot_2018-10-23_002142_localhost.png
@bradtaniguchi from these is coming so
the posts nad categories are not empty at all