Update State based on Object selection from dropdown menuHow to prevent custom views from losing state across screen orientation changesHow can I create an object based on an interface file definition in TypeScript?Cannot update during an existing state transitionHow to update parent's state in React?React setState not updating stateHow to update nested state properties in ReactUpdating an object with setState in ReactMultiple dropdown menu stateDoes React keep the order for state updates?How to correctly handle data object from REST API using fetch in React
In Toy Story, are toys the only inanimate objects that become alive? And if so, why?
A question about dihedral group
Are manifolds admitting a circle foliation covered by manifolds with a (non-trivial) circle action?
Is it rude to ask my opponent to resign an online game when they have a lost endgame?
Is torque as fundamental a concept as force?
Do index funds really have double-digit percents annual return rates?
Design of 50 ohms RF trace for 2.4GHz...Double layer FR-4 PCB
How do you get the angle of the lid from the CLI?
How did Gollum know Sauron was gathering the Haradrim to make war?
In chocolate terminology, what is the name of thinly sliced leaf-shaped toppings made from hot, smooth chocolate, used to form flower petals?
How to align values in table according to the pm and point?
Would there be balance issues if I allowed opportunity attacks against any creature, not just hostile ones?
What is the converted mana cost of land cards?
What is a "fat pointer" in Rust?
How can I design a magically-induced coma?
How to find better food in airports
How do you manage to study and have a balance in your life at the same time?
Is it safe for a student to give negative feedback in student evaluations?
Why not use futuristic pavise ballistic shields for protection?
LM317 to step voltage up
Taking the first element in a list of associations
Which is the best password hashing algorithm in .NET Core?
When making yogurt, why doesn't bad bacteria grow as well?
How Total raw is calculated for Science pack 2?
Update State based on Object selection from dropdown menu
How to prevent custom views from losing state across screen orientation changesHow can I create an object based on an interface file definition in TypeScript?Cannot update during an existing state transitionHow to update parent's state in React?React setState not updating stateHow to update nested state properties in ReactUpdating an object with setState in ReactMultiple dropdown menu stateDoes React keep the order for state updates?How to correctly handle data object from REST API using fetch in React
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have an object called TaskTypes, inside of the object it looks like this
-LJLQR7lVkbzsxAZC3JI: code: "Pest & Disease", colour: "0xf2473f", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtU: code: "Health & Safety", colour: "0x8c5de4", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtZ: code: "Structure", colour: "0x6b8e23", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtl: code: "Repairs & Maintenance", colour: "0x66a9fb", deleted: null, subTypes: …
-LJLQR7nJdpun5Tugh39: code: "Reminders", colour: "0xf2bb61", deleted: null, subTypes: null
-LUDgbjHzQpktk34u8-4: code: "Sample", colour: "0x2196f3", deleted: null, subTypes: …
-L_dAY_Aju0IBGwY9VVA: code: "test", colour: "0x03a9f4", deleted: null, subTypes: null
The first random strings is the Object Id.
I want the state of taskId to update each time I select one of those Objects, eg If I select "Pests & Disease" from the dropdown, the taskId will be "-LJLQR7lVkbzsxAZC3JI"
I have created a function to achieve this, however the state is not being updated.
this.state = id: "", taskId: null,
taskSubId: null,
taskSubSubId: null
setTaskType = (id: string) =>
console.log("ID:", id)
console.log("id.length:", id.length)
console.log("stateTaskId", (this.state as any).taskId)
if (id.length > 0)
console.log("setTaskTypeFunction", this.props.metadata.TaskTypes)
this.setState( id: id, taskId: id, taskSubId: null, taskSubSubId: null, taskType: Object.assign(, this.props.metadata.TaskTypes[id]) )
Heres my JSX
<select className="input-field-slider dropdown w-select" onClick=() => this.setTaskType("")>
<option key=taskId value=taskId>Select A Category</option>
Object.keys(taskTypes)
.sort((a, b) => taskTypes[a].code.toLowerCase() >
taskTypes[b].code.toLowerCase() ? 1 : -1)
.map(taskId =>
<option onClick=() => this.setTaskType(taskId) value=taskId key=taskId>taskTypes[taskId].code</option>)
</select>
As of now, I'm displaying the entire object in my dropdown ( pests & diseases etc) but my state is not being updated
reactjs typescript state jsx
add a comment |
I have an object called TaskTypes, inside of the object it looks like this
-LJLQR7lVkbzsxAZC3JI: code: "Pest & Disease", colour: "0xf2473f", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtU: code: "Health & Safety", colour: "0x8c5de4", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtZ: code: "Structure", colour: "0x6b8e23", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtl: code: "Repairs & Maintenance", colour: "0x66a9fb", deleted: null, subTypes: …
-LJLQR7nJdpun5Tugh39: code: "Reminders", colour: "0xf2bb61", deleted: null, subTypes: null
-LUDgbjHzQpktk34u8-4: code: "Sample", colour: "0x2196f3", deleted: null, subTypes: …
-L_dAY_Aju0IBGwY9VVA: code: "test", colour: "0x03a9f4", deleted: null, subTypes: null
The first random strings is the Object Id.
I want the state of taskId to update each time I select one of those Objects, eg If I select "Pests & Disease" from the dropdown, the taskId will be "-LJLQR7lVkbzsxAZC3JI"
I have created a function to achieve this, however the state is not being updated.
this.state = id: "", taskId: null,
taskSubId: null,
taskSubSubId: null
setTaskType = (id: string) =>
console.log("ID:", id)
console.log("id.length:", id.length)
console.log("stateTaskId", (this.state as any).taskId)
if (id.length > 0)
console.log("setTaskTypeFunction", this.props.metadata.TaskTypes)
this.setState( id: id, taskId: id, taskSubId: null, taskSubSubId: null, taskType: Object.assign(, this.props.metadata.TaskTypes[id]) )
Heres my JSX
<select className="input-field-slider dropdown w-select" onClick=() => this.setTaskType("")>
<option key=taskId value=taskId>Select A Category</option>
Object.keys(taskTypes)
.sort((a, b) => taskTypes[a].code.toLowerCase() >
taskTypes[b].code.toLowerCase() ? 1 : -1)
.map(taskId =>
<option onClick=() => this.setTaskType(taskId) value=taskId key=taskId>taskTypes[taskId].code</option>)
</select>
As of now, I'm displaying the entire object in my dropdown ( pests & diseases etc) but my state is not being updated
reactjs typescript state jsx
add a comment |
I have an object called TaskTypes, inside of the object it looks like this
-LJLQR7lVkbzsxAZC3JI: code: "Pest & Disease", colour: "0xf2473f", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtU: code: "Health & Safety", colour: "0x8c5de4", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtZ: code: "Structure", colour: "0x6b8e23", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtl: code: "Repairs & Maintenance", colour: "0x66a9fb", deleted: null, subTypes: …
-LJLQR7nJdpun5Tugh39: code: "Reminders", colour: "0xf2bb61", deleted: null, subTypes: null
-LUDgbjHzQpktk34u8-4: code: "Sample", colour: "0x2196f3", deleted: null, subTypes: …
-L_dAY_Aju0IBGwY9VVA: code: "test", colour: "0x03a9f4", deleted: null, subTypes: null
The first random strings is the Object Id.
I want the state of taskId to update each time I select one of those Objects, eg If I select "Pests & Disease" from the dropdown, the taskId will be "-LJLQR7lVkbzsxAZC3JI"
I have created a function to achieve this, however the state is not being updated.
this.state = id: "", taskId: null,
taskSubId: null,
taskSubSubId: null
setTaskType = (id: string) =>
console.log("ID:", id)
console.log("id.length:", id.length)
console.log("stateTaskId", (this.state as any).taskId)
if (id.length > 0)
console.log("setTaskTypeFunction", this.props.metadata.TaskTypes)
this.setState( id: id, taskId: id, taskSubId: null, taskSubSubId: null, taskType: Object.assign(, this.props.metadata.TaskTypes[id]) )
Heres my JSX
<select className="input-field-slider dropdown w-select" onClick=() => this.setTaskType("")>
<option key=taskId value=taskId>Select A Category</option>
Object.keys(taskTypes)
.sort((a, b) => taskTypes[a].code.toLowerCase() >
taskTypes[b].code.toLowerCase() ? 1 : -1)
.map(taskId =>
<option onClick=() => this.setTaskType(taskId) value=taskId key=taskId>taskTypes[taskId].code</option>)
</select>
As of now, I'm displaying the entire object in my dropdown ( pests & diseases etc) but my state is not being updated
reactjs typescript state jsx
I have an object called TaskTypes, inside of the object it looks like this
-LJLQR7lVkbzsxAZC3JI: code: "Pest & Disease", colour: "0xf2473f", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtU: code: "Health & Safety", colour: "0x8c5de4", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtZ: code: "Structure", colour: "0x6b8e23", deleted: null, subTypes: …
-LJLQR7mZaeBNnEhdHtl: code: "Repairs & Maintenance", colour: "0x66a9fb", deleted: null, subTypes: …
-LJLQR7nJdpun5Tugh39: code: "Reminders", colour: "0xf2bb61", deleted: null, subTypes: null
-LUDgbjHzQpktk34u8-4: code: "Sample", colour: "0x2196f3", deleted: null, subTypes: …
-L_dAY_Aju0IBGwY9VVA: code: "test", colour: "0x03a9f4", deleted: null, subTypes: null
The first random strings is the Object Id.
I want the state of taskId to update each time I select one of those Objects, eg If I select "Pests & Disease" from the dropdown, the taskId will be "-LJLQR7lVkbzsxAZC3JI"
I have created a function to achieve this, however the state is not being updated.
this.state = id: "", taskId: null,
taskSubId: null,
taskSubSubId: null
setTaskType = (id: string) =>
console.log("ID:", id)
console.log("id.length:", id.length)
console.log("stateTaskId", (this.state as any).taskId)
if (id.length > 0)
console.log("setTaskTypeFunction", this.props.metadata.TaskTypes)
this.setState( id: id, taskId: id, taskSubId: null, taskSubSubId: null, taskType: Object.assign(, this.props.metadata.TaskTypes[id]) )
Heres my JSX
<select className="input-field-slider dropdown w-select" onClick=() => this.setTaskType("")>
<option key=taskId value=taskId>Select A Category</option>
Object.keys(taskTypes)
.sort((a, b) => taskTypes[a].code.toLowerCase() >
taskTypes[b].code.toLowerCase() ? 1 : -1)
.map(taskId =>
<option onClick=() => this.setTaskType(taskId) value=taskId key=taskId>taskTypes[taskId].code</option>)
</select>
As of now, I'm displaying the entire object in my dropdown ( pests & diseases etc) but my state is not being updated
reactjs typescript state jsx
reactjs typescript state jsx
asked Mar 28 at 1:43
invrtinvrt
1119 bronze badges
1119 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
A few modifications might help.
Select change handler
setTaskType = (event) =>
const id = event.target.value;
// continue with the rest of code
JSX select element
<select className="input-field-slider dropdown w-select" value=this.state.taskId onChange=this.setTaskType>
<option value=''>Select A Category</option>
Object.keys(taskTypes)
.sort((a, b) => taskTypes[a].code.toLowerCase() >
taskTypes[b].code.toLowerCase() ? 1 : -1)
.map(taskId =>
<option value=taskId key=taskId>taskTypes[taskId].code</option>
)
</select>
Read more details at React Docs: select tag
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388970%2fupdate-state-based-on-object-selection-from-dropdown-menu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
A few modifications might help.
Select change handler
setTaskType = (event) =>
const id = event.target.value;
// continue with the rest of code
JSX select element
<select className="input-field-slider dropdown w-select" value=this.state.taskId onChange=this.setTaskType>
<option value=''>Select A Category</option>
Object.keys(taskTypes)
.sort((a, b) => taskTypes[a].code.toLowerCase() >
taskTypes[b].code.toLowerCase() ? 1 : -1)
.map(taskId =>
<option value=taskId key=taskId>taskTypes[taskId].code</option>
)
</select>
Read more details at React Docs: select tag
add a comment |
A few modifications might help.
Select change handler
setTaskType = (event) =>
const id = event.target.value;
// continue with the rest of code
JSX select element
<select className="input-field-slider dropdown w-select" value=this.state.taskId onChange=this.setTaskType>
<option value=''>Select A Category</option>
Object.keys(taskTypes)
.sort((a, b) => taskTypes[a].code.toLowerCase() >
taskTypes[b].code.toLowerCase() ? 1 : -1)
.map(taskId =>
<option value=taskId key=taskId>taskTypes[taskId].code</option>
)
</select>
Read more details at React Docs: select tag
add a comment |
A few modifications might help.
Select change handler
setTaskType = (event) =>
const id = event.target.value;
// continue with the rest of code
JSX select element
<select className="input-field-slider dropdown w-select" value=this.state.taskId onChange=this.setTaskType>
<option value=''>Select A Category</option>
Object.keys(taskTypes)
.sort((a, b) => taskTypes[a].code.toLowerCase() >
taskTypes[b].code.toLowerCase() ? 1 : -1)
.map(taskId =>
<option value=taskId key=taskId>taskTypes[taskId].code</option>
)
</select>
Read more details at React Docs: select tag
A few modifications might help.
Select change handler
setTaskType = (event) =>
const id = event.target.value;
// continue with the rest of code
JSX select element
<select className="input-field-slider dropdown w-select" value=this.state.taskId onChange=this.setTaskType>
<option value=''>Select A Category</option>
Object.keys(taskTypes)
.sort((a, b) => taskTypes[a].code.toLowerCase() >
taskTypes[b].code.toLowerCase() ? 1 : -1)
.map(taskId =>
<option value=taskId key=taskId>taskTypes[taskId].code</option>
)
</select>
Read more details at React Docs: select tag
answered Mar 28 at 3:10
Prithviraj SahuPrithviraj Sahu
2065 bronze badges
2065 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55388970%2fupdate-state-based-on-object-selection-from-dropdown-menu%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown