Can't modify string value via callback parameter - how to update object?
I'm trying to modify the value of a string via a callback, but I think my efforts are futile.
var object = {
item: {
content: ""
},
collection: []
}
function preprocess(callback) {
// ...
}
preprocess(({ collection, content }) => {
content = "new content"
collection = ["new-item-1", "new-item-2", "new-item3"];
});
console.log(object.item.content)
// => "new content"This question is about general JavaScript concepts (passing values vs references, destructuring, and callbacks) and isn't related to Sanity. You'll get better help posting this in a JavaScript-focused community like:
- Stack Overflow with the
javascripttag - r/javascript on Reddit
If you have questions about using JavaScript with Sanity — like writing GROQ queries, creating custom input components, setting up validation functions, or working with Sanity Functions — I'm happy to help with those!
Show original thread8 replies
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.