react native中使用tailwind并配置自动补全

javascript 复制代码
import { View, Text } from 'react-native';
import tw from 'twrnc';

const MyComponent = () => (
  <View style={tw`p-4 android:pt-2 bg-white dark:bg-black`}>
    <Text style={tw`text-md text-black dark:text-white`}>Hello World</Text>
  </View>
);

当然也支持条件变量

javascript 复制代码
// pass multiple args
tw.style('text-sm', 'bg-blue-100', 'flex-row mb-2');
// falsy stuff is ignored, so you can do conditionals like this
tw.style(isOpen && 'bg-blue-100');

重要的来了!配置vscode的补全

参考自React Native - Tailwind CSS autocomplete in VSCode for twrnc package

补全插件还是用的Tailwind CSS IntelliSense,需要添加vscode的配置并手动新建两个空文件

在下图添加

新建一个空文件tailwind.config.js

然后就可以了

相关推荐
vim怎么退出8 小时前
Dive into React——事件系统
前端·react.js·源码阅读
打小就很皮...10 小时前
基于 Python + LangChain + React 实现智能发票识别与验真系统实战
前端·react.js·langchain·ocr·发票识别
圣殿骑士-Khtangc21 小时前
单智能体落地实战:从 ReAct 到 Production-Ready AI Agent 全链路解析
人工智能·react.js
Patrick_Wilson1 天前
router.replace 之后紧跟 reload,页面为什么无限刷新?
javascript·react.js·浏览器
xiaofeichaichai1 天前
React Hooks
前端·javascript·react.js
wordbaby1 天前
rn-cross-calendar:一个兼容 React 18/19、RN/RNOH 的跨平台日历组件
前端·react native·harmonyos
markfeng81 天前
Redux 与 React-Redux 深度解析:从原理到最佳实践
react.js
微扬嘴角1 天前
react篇4--setState、LazyLoad和Hooks
前端·javascript·react.js
光影少年1 天前
React 项目常见优化方案
前端·react.js·前端框架
光影少年1 天前
组件复用:HOC、Render Props、自定义Hook 对比
前端·react.js·掘金·金石计划