javascript - React filtering information grabbed from an object -
so have react container working in, , need take information stored in object , filter , use variable. here @ right now:
please ignore lot of things did not filter out, aware way looks there lot of unused variables information being grabbed, used in container.
... componentdidmount() { // ... bunch of stuff doing work // need use categoryid variable inside of here // categoryid returns /s/a-12345678 need trailing numbers (12345678) } dvmcontainer.proptypes = { categoryid: proptypes.string } const mapstatetoprops = function({ config, page, profile }) { return { categoryid: page.metadata.node_id } }
if node_id in same format, can use:
categoryid: page.metadata.node_id.split('-')[1] in mapstatetoprops.
alternatively, can use regular expression:
categoryid: page.metadata.node_id.match(/[0-9]+$/)[0] this matches uninterrupted string of numbers @ end of string.
[edit] document comments in case or else in future has understand why code extracting that. in explanation, focus more on why it's being done , not what it's doing.
Comments
Post a Comment