1

I'm currently learning data structures on my own. Most websites provide an implementation using classes and I'm unable to find an implementation using functions for functional components.

I want to learn how to implement a linkedlist using Typescript in a functional component in React.

4
  • 2
    A linked list is a data structure only. A functional component relates to UI concerns. If you want to learn data structures, you shouldn't make that dependent on UI concerns. Commented Feb 19, 2024 at 8:59
  • What does it even mean for a React component to be a data structure? I don't believe you'd be doing a linked list, or a hashmap, or a heap, or anything else even if it was a class component. Commented Feb 19, 2024 at 9:24
  • 1
    As for how to make a "functional linked list" - it's easy: interface Node<T> { value: T, next: Node<T> | null }. Now you need to define functions that deal with this, like an function append<T>(Node<T>, value: T): Node<T>. Which will have the same logic you'd have if you had a class but it's not a method. Commented Feb 19, 2024 at 9:28
  • Please provide enough code so others can better understand or reproduce the problem. Commented Feb 19, 2024 at 10:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.