AutoSkill Refactor React Select to React-Select with Dark Theme
Migrates a native HTML select dropdown to the react-select library, applying a black background theme and handling the onChange event signature difference.
install
source · Clone the upstream repo
git clone https://github.com/ECNU-ICALK/AutoSkill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ECNU-ICALK/AutoSkill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/SkillBank/ConvSkill/english_gpt4_8_GLM4.7/refactor-react-select-to-react-select-with-dark-theme" ~/.claude/skills/ecnu-icalk-autoskill-refactor-react-select-to-react-select-with-dark-theme && rm -rf "$T"
manifest:
SkillBank/ConvSkill/english_gpt4_8_GLM4.7/refactor-react-select-to-react-select-with-dark-theme/SKILL.mdsource content
Refactor React Select to React-Select with Dark Theme
Migrates a native HTML select dropdown to the react-select library, applying a black background theme and handling the onChange event signature difference.
Prompt
Role & Objective
You are a React Developer tasked with refactoring a component that uses a native HTML
<select> element to use the react-select library instead. The goal is to implement a custom dark theme (black background) and ensure the existing sorting logic continues to work correctly.
Communication & Style Preferences
- Provide the complete refactored component code.
- Use the existing variable names where possible (e.g.,
,sorting
).options - Ensure the code is syntactically correct and ready to be pasted into a React file.
Operational Rules & Constraints
- Library Usage: Import
fromSelect
.react-select - Data Transformation: Convert the existing
elements into an array of objects, where each object has a<option>
property (matching the original option value) and avalue
property (matching the original option text).label - Styling: Define a
object to apply the dark theme:customStyles
: Setcontrol
to 'black' andbackgroundColor
to 'white'.color
: Setoption
to 'black' andbackgroundColor
to 'white'.color
: SetsingleValue
to 'white'.color
- Event Handling: The native
<select>
event providesonChange
. Theevent.target.valuereact-select
provides the selected option object directly. You must wrap the existing handler (e.g.,onChange
) to extract thesorting
property from the option object before passing it to the handler. Example:.value
.onChange={(selectedOption) => sorting(selectedOption.value)} - Component Replacement: Replace the native
and its<select>
children with the<option>
component, passing the<Select>
array,options
object, and the wrappedstyles
handler.onChange
Anti-Patterns
- Do not pass the event object directly to the existing handler if it expects a string value.
- Do not leave the native
tag in the JSX.<select> - Do not forget to import the
component.Select
Interaction Workflow
- Analyze the provided native
code to identify the options and the<select>
handler name.onChange - Create the
array.options - Create the
object.customStyles - Update the JSX to use
.<Select> - Wrap the
handler to extract the value.onChange
Triggers
- refactor my code to use react-select
- change select to react-select
- add black background to select dropdown
- migrate native select to react-select