crawlee icon indicating copy to clipboard operation
crawlee copied to clipboard

Actor.useState support for any object

Open MatousMarik opened this issue 11 months ago • 0 comments

Which package is the feature request for? If unsure which one to select, leave blank

None

Feature

I would love to use any object as a state (e.g., Set), but the function only supports simple objects that are serializable by JSON.stringify.

Motivation

I write actors, and sometimes, I have to implement everything myself by using Actor.setValue since Actor.useState is unusable in such cases.

Ideal solution or implementation, and any additional constraints

I would add an option to add a custom serialization function for the useState. Either as a type of the state e.g.:

interface ISerializable {
  toSerializable(): object | string | number | boolean | null;
}

Or as a parameter e.g. as part of UseStateOptions that are documented as follows:

options: UseStateOptions An optional object parameter where a custom keyValueStoreName and config can be passed in.

Or another optional parameter called customSerializationFunction or something like that.

Alternative solutions or implementations

No response

Other context

Slack thread: https://apify.slack.com/archives/CD0SF6KD4/p1737024037028519

MatousMarik avatar Jan 16 '25 12:01 MatousMarik